Repository navigation
fix: honour -C in the statusline and in every supplied path - #3567
Merged
Merged
Conversation
`-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.
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.
# Conflicts: # src/git/mod.rs
max-sixty
marked this pull request as ready for review
July 24, 2026 22:42
worktrunk-bot
approved these changes
Jul 24, 2026
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]>
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.
-Csets the repository discovery path but never chdir's the process, so anything readingstd::env::current_dir()silently ignores it. Two places did.wt list statuslinedescribed the wrong worktreewt -C /path/to/other/worktree list statuslineprinted 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=jsonwas mostly right already. It picked its worktree viacurrent_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 tocurrent_worktree()and thecwdbinding is gone.git_status_segmentsnow takes aWorkingTreeinstead of(&Repository, &Path). That also settles a split inside it: the worktree lookup used the cwd while the no-worktree fallback usedrepo.current_worktree().--format=claude-codeis 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-Ctoo.Four integration tests. Three run from the main worktree with
-Cpointed at afeatureworktree, 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 whilelist_worktreescomes from wt's discovery path, so nothing matches and only the branch is reported. That fallback previously had no test, which is whatcodecov/patchcaught on the first push.Discovering the
Repositoryfrom the stdin directory instead would remove that split, but it would miss theprewarmcache (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
-Cwt switch ../repo.featureandwt remove ../repo.featurejoined the argument onto the process cwd. With-Cin play that split the invocation in two — wt chose the repository, the shell chose the path — and the combination resolved to nothing, soswitchreported "No branch named ../repo.feature".--config,WORKTRUNK_CONFIG_PATH,WORKTRUNK_SYSTEM_CONFIG_PATH, and the trace file ofwt config state logs profilename a file the same way and had the same gap:wt -C repo --config mycfg.toml config showreported "Config file not found" for a file sitting inrepo/.Git resolves the paths in its command line against its own
-C, because it chdir's there before doing anything else. wt's-Csets a discovery path instead, soresolve_input_pathjoins onto that — one resolution point for all five, so they cannot drift apart. It returns the path untouched when-Cwas not given, rather than joining.onto it: the process cwd already resolves those, and the join would surface as a stray./in output.Path::joinleaves an absolute path alone, which drops anis_absolutebranch and, inresolve.rs, a falliblecurrent_dir()call.Three neighbours are deliberately outside the rule, and the docstring says why:
git worktree list, an XDG config directory — arrive absolute.WORKTRUNK_PROJECT_CONFIG_PATHresolves from the worktree root, its documented base, because the project config is per-worktree.WORKTRUNK_BINandXDG_CONFIG_DIRSare 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
-Cpointed 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:switchwith "No branch named ../repo.feature-detached",removeby leaving the worktree standing, and the two config paths by not finding their file.The
set_base_pathdocstring picks up the rule, so the next reader has one place to find it:-Cis 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_jsonandgit_status_segmentsduplicate the worktree-lookup-and-populate sequence (list_worktrees→ find by root →is_home→build_worktree_item→populate_itemwith identicalCollectOptions). Worth collapsing separately.