Skip to content

refactor(list): extract WorktreePresence for the worktree gutter arm - #3154

Merged
max-sixty merged 2 commits into
mainfrom
gutter-search
Jun 22, 2026
Merged

max-sixty merged 2 commits into
mainfrom
gutter-search

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

What

Extracts the worktree gutter-glyph classification in ItemKind::gutter_glyph() from an inline if is_current { '@' } else if is_main { '^' } else { '+' } into a typed WorktreePresence enum (Current/Primary/Linked) with its own gutter_glyph(), plus a WorktreeData::presence() accessor. Both match arms now read symmetrically: data.presence().gutter_glyph() for worktrees, scope.gutter_glyph() for branches (the existing BranchScope).

Why

The worktree arm was the one place still hand-rolling the gutter precedence inline, while branch rows already had the typed BranchScope. Extracting it gives the precedence rule a name and a single documented home, finishing the symmetry the gutter-search work started.

Derived, not stored

WorktreePresence is computed from WorktreeData (via presence()), not stored like BranchScope. is_current and is_main are orthogonal bits (the main worktree is also current when you sit in it), and is_main is consumed independently by the status column (render.rs), the status tier (MainState::IsMain), and JSON output. So the pair can't collapse into a single stored 3-variant discriminant without losing the is_main bit for a current-and-main worktree. The enum's doc records this, so a future reader doesn't try to "simplify" it into a stored field. is_current wins when both bits are set.

Behavior

Byte-identical — no snapshot churn. The existing gutter_glyph_marks_each_row_kind test gains the previously-untested both-current-and-primary precedence case (@ wins over ^).

This was written by Claude Code on behalf of max

max-sixty and others added 2 commits June 21, 2026 18:45
ItemKind::gutter_glyph's worktree arm branched inline on is_current and
is_main. Extract that precedence into a typed WorktreePresence enum
(Current/Primary/Linked) with its own gutter_glyph, mirroring BranchScope
so both match arms read X.gutter_glyph().

WorktreePresence is derived from WorktreeData (via WorktreeData::presence),
not stored like BranchScope: is_current and is_main are orthogonal bits (the
main worktree is also current when you sit in it), and is_main is consumed
independently by the status column and JSON, so the pair can't collapse into
one stored discriminant. is_current wins when both are set.

Behavior is byte-identical (no snapshot churn); adds the previously untested
both-current-and-primary precedence case to the gutter test.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit 494b014 into main Jun 22, 2026
36 checks passed
@max-sixty
max-sixty deleted the gutter-search branch June 22, 2026 02:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants