Skip to content

fix(list): flag no worktree primary when none holds the default branch - #4785

Merged
max-sixty merged 1 commit into
mainfrom
agent-a974204f832f65ef6
Nov 15, 2026
Merged

max-sixty merged 1 commit into
mainfrom
agent-a974204f832f65ef6

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

In a bare repo where every worktree is detached, as a jj-colocated repo leaves them, wt list marked whichever worktree git listed first as the primary one: ^ in the gutter and status, "main": true in JSON, its ahead/behind hidden, and every path shortened relative to it. wt list had a fallback of its own to the first non-prunable worktree when Repository::primary_worktree() returned None, while every other consumer (the statusline, removal, home_path(), copy-ignored, {{ primary_worktree_path }}) reads None as "no primary". With the fallback gone, wt list agrees with wt list statusline: no row is primary, and paths are shortened relative to the repo root, where home_path() points.

Worth weighing: a bare repo whose worktrees are all on non-default branches also loses its ^ row, which matches the AGENTS.md definition of the primary worktree. Non-bare repos are unchanged, since their primary is the main worktree whatever its HEAD.

johnstegeman reported this in rex-config#11; jj support is tracked in #926. Requested by max-sixty. A new bare-repo test fails without the fix and passes with it, and the list, statusline, JSON, picker, prune and remove integration tests pass.

This was written by Claude Code on behalf of max-sixty

In a bare repo whose worktrees are all detached, as jj leaves a colocated
repo, `wt list` marked an arbitrary worktree as the primary one: `^` in the
gutter and status, `"main": true` in JSON, ahead/behind against the default
branch hidden, and every path shortened relative to it.

`collect()` chose the main row with its own fallback. When
`Repository::primary_worktree()` returned `None`, which it does for a bare repo
with no worktree on the default branch, it took the first non-prunable worktree
in git's listing order. Git sorts linked worktrees by path, so `feat/` beat
`main/`. Every other consumer of the primary worktree (statusline, removal,
`home_path()`, `copy-ignored`, `{{ primary_worktree_path }}`, the project-config
lookup) uses `primary_worktree()` directly, so `wt list` disagreed with
`wt list statusline` about the same worktree.

`collect()` now uses `primary_worktree()` with no fallback. When it is `None`,
no row is primary and paths are shortened relative to the repo root, the same
place `home_path()` resolves to. Non-bare repos are unaffected, since their
primary is the main worktree whatever its HEAD. The removal guards never read
this flag: they check `is_linked()` and the default branch by name.
@max-sixty
max-sixty merged commit 47d0a56 into main Nov 15, 2026
37 checks passed
@max-sixty
max-sixty deleted the agent-a974204f832f65ef6 branch November 15, 2026 18:35
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