Coverage for src/workstack/cli/commands/tree.py: 87%
15 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-19 09:31 -0400
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-19 09:31 -0400
1"""Tree visualization command for workstack."""
3from pathlib import Path
5import click
7from workstack.cli.core import discover_repo_context
8from workstack.cli.tree import build_workstack_tree, render_tree
9from workstack.core.context import WorkstackContext
12@click.command("tree")
13@click.pass_obj
14def tree_cmd(ctx: WorkstackContext) -> None:
15 """Display tree of worktrees with their dependencies.
17 Shows ONLY branches that have active worktrees, organized
18 by their Graphite parent-child relationships.
20 Requires Graphite to be enabled and configured.
22 Example:
23 $ workstack tree
24 main [@root]
25 ├─ feature-a [@feature-a]
26 │ └─ feature-a-2 [@feature-a-2]
27 └─ feature-b [@feature-b]
29 Legend:
30 [@worktree-name] = worktree directory name
31 Current worktree is highlighted in bright green
32 """
33 repo = discover_repo_context(ctx, Path.cwd())
35 # Build tree structure (will exit with error if Graphite cache missing)
36 roots = build_workstack_tree(ctx, repo.root)
38 if not roots:
39 click.echo("No worktrees found", err=True)
40 raise SystemExit(1)
42 # Render and display
43 tree_output = render_tree(roots)
44 click.echo(tree_output)