Repository navigation
fix(repo): honor git's scope rules for core.worktree in repo_path() - #2362
Merged
Merged
Conversation
#2350 introduced a divergence for normal repos where the user has set `core.worktree` in global/system config: `git config --list -z` merges all scopes into the bulk map, but git itself only honors `core.worktree` from local config for worktree discovery. We were trusting the merged value and returning (e.g.) a stray global path as the repo root. Delegate to `git rev-parse --show-toplevel` only when the bulk map reports `core.worktree` — git then applies its own scope rules. The common case (no `core.worktree` anywhere) still skips the subprocess, which is the whole point of this path. Submodules now pay one fork back, matching pre-#2350 behavior for that minority case. Caught by Codex review of #2350. Co-Authored-By: Claude <[email protected]>
worktrunk-bot
approved these changes
Apr 21, 2026
max-sixty
added a commit
that referenced
this pull request
Apr 21, 2026
Doc-only follow-up to #2350 / #2362. The docstring on `Repository::repo_path()` had grown to ~45 lines during the scope-handling fix; trimming it to ~25 without dropping any of the reasoning that would cause accidental regressions. Kept (load-bearing): - Why we anchor on `git_common_dir` (linked-worktree invariant) - The three-case resolution table - Why submodules need `core.worktree` (or someone removes the probe) - Why we delegate to `rev-parse` instead of trusting the bulk map directly (or someone re-introduces the #2350 scope bug) - The "common case skips the subprocess" perf note (or someone always probes) Trimmed: - "# Why we anchor" heading → folded into the lead-in - "(or `[includeIf]`-imported)" parenthetical - One redundant sentence restating that git ignores global `core.worktree` - Minor phrasing cleanup > _This was written by Claude Code on behalf of @max-sixty_ Co-authored-by: Claude <[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.
Summary
#2350 introduced a divergence for a narrow case: normal non-bare repos where a user has set
core.worktreein global/system config.git config --list -zmerges scopes into the bulk map, but git itself only honorscore.worktreefrom local config for worktree discovery — so we'd return (e.g.) a stray global path as the repo root while git would return the actual worktree.Fix: when the bulk map reports
core.worktree, delegate togit rev-parse --show-toplevelso git applies its own scope rules. The common case (nocore.worktreeanywhere — the vast majority of repos) still skips the subprocess entirely; that was the whole point of #2350. Submodules pay one fork back, matching pre-#2350 behavior for that minority case.Caught by Codex review of the merged #2350.
Correctness
Verified against git (all from inside
.git):core.worktreescopegit rev-parse --show-toplevel#2350)parent(.git)✓parent(.git)✓Tests
repo_path_ignores_non_local_core_worktree— pre-populates the bulk config cache with acore.worktreevalue but leaves the on-disk.git/configempty, sorev-parse --show-toplevelfails and we fall through toparent(.git). Simulates the global-only scope case.test_repo_path_in_submoduleintegration test still passes (localcore.worktreein a real submodule).Performance
No regression for the common case (no
core.worktreeanywhere): still skips the subprocess. Submodules pay one fork — same as pre-#2350.Ref #2322