Coverage for src/workstack/cli/commands/status.py: 42%
31 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"""Status command implementation."""
3from pathlib import Path
5import click
7from workstack.cli.core import discover_repo_context
8from workstack.core.context import WorkstackContext
9from workstack.status.collectors.git import GitStatusCollector
10from workstack.status.collectors.github import GitHubPRCollector
11from workstack.status.collectors.graphite import GraphiteStackCollector
12from workstack.status.collectors.plan import PlanFileCollector
13from workstack.status.orchestrator import StatusOrchestrator
14from workstack.status.renderers.simple import SimpleRenderer
17@click.command("status")
18@click.pass_obj
19def status_cmd(ctx: WorkstackContext) -> None:
20 """Show comprehensive status of current worktree."""
21 # Discover repository context
22 repo = discover_repo_context(ctx, Path.cwd())
23 current_dir = Path.cwd().resolve()
25 # Find which worktree we're in
26 worktrees = ctx.git_ops.list_worktrees(repo.root)
27 current_worktree_path = None
29 for wt in worktrees:
30 # Check path exists before resolution/comparison to avoid OSError
31 if wt.path.exists():
32 wt_path_resolved = wt.path.resolve()
33 # Use is_relative_to only after confirming path exists
34 if current_dir == wt_path_resolved or current_dir.is_relative_to(wt_path_resolved):
35 current_worktree_path = wt_path_resolved
36 break
38 if current_worktree_path is None:
39 click.echo("Error: Not in a git worktree", err=True)
40 raise SystemExit(1)
42 # Create collectors
43 collectors = [
44 GitStatusCollector(),
45 GraphiteStackCollector(),
46 GitHubPRCollector(),
47 PlanFileCollector(),
48 ]
50 # Create orchestrator
51 orchestrator = StatusOrchestrator(collectors)
53 # Collect status
54 status = orchestrator.collect_status(ctx, current_worktree_path, repo.root)
56 # Render status
57 renderer = SimpleRenderer()
58 renderer.render(status)