Skip to content

fix: honour -C in the statusline and in every supplied path - #3567

Merged
max-sixty merged 5 commits into
mainfrom
statusline-honors-c-flag
Jul 24, 2026
Merged

max-sixty merged 5 commits into
mainfrom
statusline-honors-c-flag

Conversation

@max-sixty

@max-sixty max-sixty commented Jul 24, 2026 •

Copy link
Copy Markdown
Owner

-C sets the repository discovery path but never chdir's the process, so anything reading std::env::current_dir() silently ignores it. Two places did.

wt list statusline described the wrong worktree

wt -C /path/to/other/worktree list statusline printed the statusline for the cwd's worktree, and from a directory outside any repo it printed nothing at all.

Both formats now resolve their worktree through Repository::current_worktree(), which anchors to the discovery path. That accessor already exists for this bug class (its docstring cites #2625), so this is routing the statusline onto the canonical path rather than adding a new one.

Details worth knowing while reading the diff:

  • --format=json was mostly right already. It picked its worktree via current_worktree() and only its "are we in a worktree" gate read the cwd, so it misbehaved just when the process cwd sat outside a repo (printed []). That gate moves to current_worktree() and the cwd binding is gone.
  • git_status_segments now takes a WorkingTree instead of (&Repository, &Path). That also settles a split inside it: the worktree lookup used the cwd while the no-worktree fallback used repo.current_worktree().
  • --format=claude-code is unchanged where it matters. The directory Claude Code sends on stdin still wins, since that names the session's directory rather than wt's. With no stdin it falls back to the same worktree as the other formats, so it honours -C too.

Four integration tests. Three run from the main worktree with -C pointed at a feature worktree, one per format; the existing statusline tests all set the child's cwd, which is the route that already worked. The fourth pins the claude-code split: when stdin names a directory in a different repository, the worktree comes from stdin while list_worktrees comes from wt's discovery path, so nothing matches and only the branch is reported. That fallback previously had no test, which is what codecov/patch caught on the first push.

Discovering the Repository from the stdin directory instead would remove that split, but it would miss the prewarm cache (keyed on the base path) that this prompt-redraw hot path depends on, so the split stays and is now asserted rather than incidental.

Supplied paths resolved from the shell, not from -C

wt switch ../repo.feature and wt remove ../repo.feature joined the argument onto the process cwd. With -C in play that split the invocation in two — wt chose the repository, the shell chose the path — and the combination resolved to nothing, so switch reported "No branch named ../repo.feature". --config, WORKTRUNK_CONFIG_PATH, WORKTRUNK_SYSTEM_CONFIG_PATH, and the trace file of wt config state logs profile name a file the same way and had the same gap: wt -C repo --config mycfg.toml config show reported "Config file not found" for a file sitting in repo/.

Git resolves the paths in its command line against its own -C, because it chdir's there before doing anything else. wt's -C sets a discovery path instead, so resolve_input_path joins onto that — one resolution point for all five, so they cannot drift apart. It returns the path untouched when -C was not given, rather than joining . onto it: the process cwd already resolves those, and the join would surface as a stray ./ in output. Path::join leaves an absolute path alone, which drops an is_absolute branch and, in resolve.rs, a fallible current_dir() call.

Three neighbours are deliberately outside the rule, and the docstring says why:

  • Paths wt derives itself — a worktree root from git worktree list, an XDG config directory — arrive absolute.
  • WORKTRUNK_PROJECT_CONFIG_PATH resolves from the worktree root, its documented base, because the project config is per-worktree.
  • WORKTRUNK_BIN and XDG_CONFIG_DIRS are never opened by wt: the first is expanded later by the generated shell wrapper, and the XDG spec already requires the second to be absolute.

Four integration tests, one per surface, each running from outside the repo with -C pointed into it — the neighbouring tests run from a cwd inside the repo, which is the route that works under either rule. All four fail against the old code: switch with "No branch named ../repo.feature-detached", remove by leaving the worktree standing, and the two config paths by not finding their file.

The set_base_path docstring picks up the rule, so the next reader has one place to find it: -C is the base for the two things git takes from its chdir — the repository discovered, and every path the user names — while the process cwd stays the answer to where the user's shell physically is.

Noticed, not touched

run_json and git_status_segments duplicate the worktree-lookup-and-populate sequence (list_worktrees → find by root → is_home → build_worktree_item → populate_item with identical CollectOptions). Worth collapsing separately.

This was written by Claude Code on behalf of max

`-C` sets the repository discovery path without chdir'ing the process, so
`std::env::current_dir()` silently ignores it. The table format read the
process cwd for both its worktree lookup and its "are we in a worktree" gate,
so `wt -C <path> list statusline` described the cwd's worktree; from outside a
repo it printed nothing at all.

Route both formats through `Repository::current_worktree()`, which resolves
against the discovery path. `--format=json` already picked its worktree that
way and only its gate read the cwd, so its output was right except when the
process cwd sat outside a repo. `git_status_segments` now takes a
`WorkingTree`, which also settles a split inside it: the lookup used the cwd
while its no-worktree fallback used `current_worktree()`.

`--format=claude-code` still takes the directory Claude Code sends on stdin,
since that names the session's directory rather than wt's; with no stdin it
falls back to the same worktree as the other formats.
The stdin-directory path can land in a repository other than the one wt
discovered, in which case the directory matches none of the discovered repo's
worktrees and only its branch can be reported. That branch of
git_status_segments had no test, so changing its line surfaced as a
codecov/patch miss.
`wt switch ../repo.feature` and `wt remove ../repo.feature` joined the
argument onto the process cwd, so `-C` chose the repository while the
shell chose the path — a combination that silently resolved to nothing.
Git resolves path arguments against its own `-C` (it chdir's there), so
both now join onto `Repository::discovery_path()`, which is the `-C`
value and otherwise the process cwd, leaving unflagged invocations
unchanged.

`set_base_path` gets the rule: `-C` is the base for the two things git
takes from its chdir — the repository discovered and any relative path
argument — while the process cwd stays the answer to where the user's
shell physically is.
@max-sixty max-sixty changed the title fix(statusline): honour -C when selecting the worktree fix: honour -C in the statusline and in relative path arguments Jul 24, 2026
The worktree path arguments were the visible case, but `--config`,
`WORKTRUNK_CONFIG_PATH`, `WORKTRUNK_SYSTEM_CONFIG_PATH`, and the trace
file of `wt config state logs profile` name files the same way, and each
was read from the process cwd — so `wt -C repo --config mycfg.toml`
reported "Config file not found" for a file git's rule would have found.

`resolve_input_path` is now the single resolution point, so the sites
cannot drift apart. It returns the path untouched when `-C` was not
given, rather than joining `.` onto it: the process cwd already resolves
those, and the join would surface as a stray `./` in output.

Three neighbours stay outside the rule, and the docstring says why:
paths wt derives itself are already absolute,
`WORKTRUNK_PROJECT_CONFIG_PATH` resolves from the worktree root because
the project config is per-worktree, and `WORKTRUNK_BIN` /
`XDG_CONFIG_DIRS` are never opened by wt at all.
@max-sixty max-sixty changed the title fix: honour -C in the statusline and in relative path arguments fix: honour -C in the statusline and in every supplied path Jul 24, 2026
@max-sixty
max-sixty marked this pull request as ready for review July 24, 2026 22:42
@max-sixty
max-sixty merged commit edcfe5f into main Jul 24, 2026
39 checks passed
@max-sixty
max-sixty deleted the statusline-honors-c-flag branch July 24, 2026 22:57
max-sixty added a commit that referenced this pull request Jul 25, 2026
…3583)

Documents three user-facing fixes that landed on `main` after the
v0.69.1 release branch was cut. They shipped in the v0.69.1 binary (the
release squash-merged onto the current `main` tip) but weren't yet in
the `## 0.69.1` changelog section, so this adds them under 0.69.1 where
they belong — no version change.

- **#3567** — `wt -C` honoured by `wt list statusline`
- **#3579** — `wt step squash`/`wt step commit` refuse to commit
unresolved conflicts; unified `wt list` operation gutter symbol
- **#3560** — `wt switch` picker cancels its orphaned background preview
processes on exit

Each was independently reviewed for the data-loss surface as part of the
release (all clean; #3579 is safety-positive).

> _This was written by Claude Code on behalf of max_

Co-authored-by: Claude Sonnet 5 <[email protected]>
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