diff --git a/src/git_worm/routes/new.py b/src/git_worm/routes/new.py index b7e6ddd..66feb1d 100644 --- a/src/git_worm/routes/new.py +++ b/src/git_worm/routes/new.py @@ -1,3 +1,4 @@ +from collections import defaultdict import subprocess from typing import Annotated @@ -9,7 +10,6 @@ TextColumn, ) from xclif import Arg, Option, WithConfig, command, console -from xclif.context import get_context from git_worm.config import load_config from git_worm.files import ( @@ -136,24 +136,21 @@ def on_progress(completed: int, total: int, name: str, action: str) -> None: ) # Print summary - copied = [r for r in results if r["action"] != "ignored"] console.print( f"[bold green]Created worktree[/bold green] [bold]{b}[/bold] @ [dim]{wt_path}[/dim]" ) - if results and get_context().verbosity >= 1: - if copied: - console.print(f"[dim]Copied {len(copied)} ignored file(s)[/dim]") + if results: + groups: dict[str, list[str]] = defaultdict(list) for r in results: - action = r["action"] - name = r["name"] + groups[r["action"]].append(r["name"]) + for action in sorted(groups.keys()): + items = sorted(groups[action]) icon = _ACTION_ICONS.get(action, "+") color = _ACTION_COLORS.get(action, "green") - if action == "ignored": - console.print(f" [dim]{icon} {name} ({action})[/dim]") - else: - console.print( - f" [{color}]{icon}[/{color}] {name} [dim]({action})[/dim]" - ) + label = action.title() if action != "COW" else action + console.print(f" [{color}]{label} ({len(items)})[/{color}]") + for name in items: + console.print(f" [{color}]{icon}[/{color}] {name}") # Print hint if node_modules was skipped and no post_create hook ran install if should_skip_node_modules(repo): diff --git a/src/git_worm/routes/prune.py b/src/git_worm/routes/prune.py index 5663649..e29cf05 100644 --- a/src/git_worm/routes/prune.py +++ b/src/git_worm/routes/prune.py @@ -85,12 +85,22 @@ def _( console.print("[dim]Aborted.[/dim]") return + pruned_stale = [] if stale_lines: subprocess.run(["git", "worktree", "prune", "--verbose", "--expire=now"], check=True, capture_output=True, text=True) - for line in stale_lines: - console.print(f"[dim]pruned:[/dim] {line}") + pruned_stale = stale_lines + pruned_merged = [] for wt in merged_worktrees: path = Path(wt["path"]) remove_worktree(path) - console.print(f"[bold green]Removed merged worktree[/bold green] [bold]{wt['branch']}[/bold]") + pruned_merged.append(wt) + + if pruned_stale or pruned_merged: + console.print(f"[bold green]Pruned ({len(pruned_stale) + len(pruned_merged)})[/bold green]") + for line in pruned_stale: + console.print(f" [red]-[/red] [dim]{line}[/dim]") + for wt in pruned_merged: + console.print(f" [red]-[/red] [bold]{wt['branch']}[/bold]") + else: + console.print("[dim]Nothing pruned.[/dim]") diff --git a/src/git_worm/routes/remove.py b/src/git_worm/routes/remove.py index 72c9fee..09b2aee 100644 --- a/src/git_worm/routes/remove.py +++ b/src/git_worm/routes/remove.py @@ -62,9 +62,15 @@ def _( console.print("[dim]Aborted.[/dim]") return + removed = [] for b, wt_path in to_remove: remove_worktree(wt_path, force=force) - console.print(f"[bold green]Removed worktree[/bold green] [bold]{b}[/bold]") + removed.append(b) + + if removed: + console.print(f"[bold green]Removed ({len(removed)})[/bold green]") + for name in removed: + console.print(f" [red]-[/red] [bold]{name}[/bold]") if failed: return 1 diff --git a/tests/test_commands.py b/tests/test_commands.py index 756acb9..09c8643 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -37,6 +37,9 @@ def test_new_copies_gitignored_files(git_repo, capsys): result = cli.root_command.execute(["new", "feat-env"]) assert result == 0 assert (git_repo / ".worktrees" / "feat-env" / ".env").read_text() == "SECRET=42" + out = capsys.readouterr().out + assert "Copied (1)" in out + assert "+ .env" in out def test_new_creates_worktree_gitignore(git_repo, capsys): @@ -62,10 +65,30 @@ def test_rm_removes_worktree(git_repo, capsys): cli = _make_cli() cli.root_command.execute(["new", "feat-rm"]) assert (git_repo / ".worktrees" / "feat-rm").exists() + capsys.readouterr() result = cli.root_command.execute(["rm", "feat-rm", "--yes"]) assert result == 0 assert not (git_repo / ".worktrees" / "feat-rm").exists() + out = capsys.readouterr().out + assert "Removed (1)" in out + assert "- feat-rm" in out + + +def test_rm_removes_multiple_worktrees(git_repo, capsys): + cli = _make_cli() + cli.root_command.execute(["new", "feat-rm-one", "feat-rm-two"]) + capsys.readouterr() + + result = cli.root_command.execute(["rm", "feat-rm-one", "feat-rm-two", "--yes"]) + + assert result == 0 + out = capsys.readouterr().out + assert "Removed (2)" in out + assert "- feat-rm-one" in out + assert "- feat-rm-two" in out + assert not (git_repo / ".worktrees" / "feat-rm-one").exists() + assert not (git_repo / ".worktrees" / "feat-rm-two").exists() def test_rm_dirty_worktree_without_force(git_repo, capsys): @@ -288,10 +311,13 @@ def test_prune_merged_removes_merged_worktrees(git_repo, capsys): ) assert wt_path.exists() + capsys.readouterr() result = cli.root_command.execute(["clean", "--yes"]) assert result == 0 assert not wt_path.exists() out = capsys.readouterr().out + assert "Pruned (1)" in out + assert "- feat-merged" in out assert "feat-merged" in out @@ -301,9 +327,12 @@ def test_prune_removes_recent_missing_worktree(git_repo, capsys): wt_path = git_repo / ".worktrees" / "feat-missing" shutil.rmtree(wt_path) + capsys.readouterr() result = cli.root_command.execute(["clean", "--yes"]) assert result == 0 + out = capsys.readouterr().out + assert "Pruned (1)" in out worktrees = subprocess.run( ["git", "worktree", "list", "--porcelain"], cwd=git_repo,