Repository navigation
fix(list): flag no worktree primary when none holds the default branch - #4785
Merged
Merged
Conversation
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.
worktrunk-bot
approved these changes
Nov 14, 2026
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In a bare repo where every worktree is detached, as a jj-colocated repo leaves them,
wt listmarked whichever worktree git listed first as the primary one:^in the gutter and status,"main": truein JSON, its ahead/behind hidden, and every path shortened relative to it.wt listhad a fallback of its own to the first non-prunable worktree whenRepository::primary_worktree()returnedNone, while every other consumer (the statusline, removal,home_path(),copy-ignored,{{ primary_worktree_path }}) readsNoneas "no primary". With the fallback gone,wt listagrees withwt list statusline: no row is primary, and paths are shortened relative to the repo root, wherehome_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.