Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions devflow/cli/commands/cleanup_clones_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def _payload(entry: CloneCacheEntry, names: dict[Path, str]) -> dict[str, Any]:
"last_activity": entry.last_used,
"status": entry.status,
"reason": entry.reason,
"reason_code": entry.reason_code,
"repositories": list(entry.repositories),
}

Expand Down Expand Up @@ -83,17 +84,27 @@ def cleanup_clones(
entries = cache.inspect()
manager = SessionManager(config_loader)
names = _session_names(entries, manager)
eligible = [entry for entry in entries if entry.eligible]
no_candidates = (
"No removable clone-cache entries found; all retained entries are protected."
if entries
else "No managed clone-cache entries found."
)

if output_json_mode:
if not select and not all_entries:
output_json(True, {"entries": [_payload(item, names) for item in entries]})
output_json(
True,
{
"entries": [_payload(item, names) for item in entries],
"eligible": [_payload(item, names) for item in eligible],
"message": no_candidates if not eligible else None,
},
)
return
elif entries:
_print_entries(entries, names)
elif not output_json_mode:
console.print("No managed clone-cache entries found.")

eligible = [entry for entry in entries if entry.eligible]
selected: list[CloneCacheEntry] = []
if all_entries:
selected = eligible
Expand All @@ -109,6 +120,9 @@ def cleanup_clones(
if entry and entry not in selected:
selected.append(entry)
elif not is_non_interactive(output_json_mode):
if not eligible:
console.print(no_candidates)
return
answer = Prompt.ask("Select entries by number/path, or 'all'", default="")
if answer.strip().lower() == "all":
selected = eligible
Expand All @@ -133,6 +147,8 @@ def cleanup_clones(
"refused": [],
},
)
elif not eligible:
console.print(no_candidates)
return

if not output_json_mode:
Expand Down
Loading
Loading