Coverage for src/workstack/status/collectors/graphite.py: 32%
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"""Graphite stack collector."""
3from pathlib import Path
5from workstack.cli.graphite import get_branch_stack
6from workstack.core.context import WorkstackContext
7from workstack.status.collectors.base import StatusCollector
8from workstack.status.models.status_data import StackPosition
11class GraphiteStackCollector(StatusCollector):
12 """Collects Graphite stack position information."""
14 @property
15 def name(self) -> str:
16 """Name identifier for this collector."""
17 return "stack"
19 def is_available(self, ctx: WorkstackContext, worktree_path: Path) -> bool:
20 """Check if Graphite is enabled and available.
22 Args:
23 ctx: Workstack context
24 worktree_path: Path to worktree
26 Returns:
27 True if Graphite is enabled
28 """
29 if not ctx.global_config_ops.get_use_graphite():
30 return False
32 if not worktree_path.exists():
33 return False
35 return True
37 def collect(
38 self, ctx: WorkstackContext, worktree_path: Path, repo_root: Path
39 ) -> StackPosition | None:
40 """Collect Graphite stack information.
42 Args:
43 ctx: Workstack context
44 worktree_path: Path to worktree
45 repo_root: Repository root path
47 Returns:
48 StackPosition with stack information or None if collection fails
49 """
50 branch = ctx.git_ops.get_current_branch(worktree_path)
51 if branch is None:
52 return None
54 # Get the stack for current branch
55 stack = get_branch_stack(ctx, repo_root, branch)
56 if stack is None:
57 return None
59 # Find current branch position in stack
60 if branch not in stack:
61 return None
63 current_idx = stack.index(branch)
65 # Determine parent and children
66 parent_branch = stack[current_idx - 1] if current_idx > 0 else None
68 children_branches = []
69 if current_idx < len(stack) - 1:
70 children_branches.append(stack[current_idx + 1])
72 # Check if this is trunk
73 is_trunk = current_idx == 0
75 return StackPosition(
76 stack=stack,
77 current_branch=branch,
78 parent_branch=parent_branch,
79 children_branches=children_branches,
80 is_trunk=is_trunk,
81 )