Repository navigation
feat(bare-repo): add worktrunk.worktree-path git-config key (split from #2951) - #2953
worktrunk-bot wants to merge 4 commits into
Conversation
The bare-repo `worktree-path` prompt previously hardcoded `feature-auth` in
the example paths regardless of the branch being switched to, which produced
a confusing mismatch (switching to `main` showed `project/.git.feature-auth`).
Use the branch identifier instead so the example matches reality.
Symbolic identifiers (`-`, `@`, `^`, `pr:N`, `mr:N`) aren't real branch
names yet — the prompt would show the literal symbol in the example path.
Skip the prompt for those; it surfaces on the next switch with a concrete
branch.
Also fix `wt config create --project` in a bare repo with no linked
worktrees yet: instead of the bare "Cannot determine project config
location — no worktree found" error, point the user at the right next
step ("run `wt switch <branch>` to create a worktree first").
Restructure the Tips & Patterns bare-repo section to walk through the
automatic prompt, the project-scoped config it writes, and the
`wt config create --project` follow-up.
Co-Authored-By: Adriano Machado <[email protected]>
Co-Authored-By: Claude Opus 4.7 <[email protected]>
The `[projects."github.com/owner/repo"]` user-config stanza is derived from the remote URL and applies to every local clone of that repository. A user with both a bare clone (`myproject/.git`) and a regular clone of the same repo cannot give them different layouts via the per-project TOML; setting it for one clobbers the other. Add a per-clone scope: `worktrunk.worktree-path` in the repo's `.git/config`. The resolution chain becomes env var → git config → user config (per-remote or global) → default, so the per-clone setting overrides the per-remote default for that clone only. Switch the bare-repo `worktree-path` prompt to write to git config when accepted, since the prompt diagnoses a clone-specific problem. Skip the prompt entirely if `worktrunk.worktree-path` is already set in git config (idempotent on re-run). Suppress the trailing `wt config create` hint when the prompt has already set git config, so the user doesn't see contradictory advice. Document the three scopes (per-clone, per-remote, global) in `wt config create --help`, the docs site config page, and the tips & patterns bare-repo section. Co-Authored-By: Adriano Machado <[email protected]> Co-Authored-By: Claude Opus 4.7 <[email protected]>
b1f38ba to
32a3ac7
Compare
|
@ammachado thanks for the other PR! for this: what is the argument for it? that someone has multiple clones of the same repo and some are bare and some are not? |
|
Yes — the trigger is "user has (or will have) more than one clone of this repo, with at least one of them bare". The concrete failure mode the PR description sketches:
Putting the override in A secondary motivation is that it lets a user with two bare clones at different paths choose different layouts without one stomping the other, but the multi-clone-mixed-layout case is the main one. |
Resolve conflicts after #2951 landed. All conflicts kept the PR-side (this-clone git-config) approach since that is the PR's purpose; main's remaining changes here were the older user-config behavior that this PR replaces. Co-Authored-By: Claude Opus 4.7 <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
Self-review on the second commit (feat(bare-repo): add worktrunk.worktree-path git-config-scope key). The first commit landed via #2951 and is already on main. The git-config-scope design is clean — env > git config > user config (per-remote or global) > default, with the prompt writing into .git/config so multi-clone setups can diverge. Two findings:
1. set_project_worktree_path is now dead code. The only production caller was offer_bare_repo_worktree_path_fix in src/commands/worktree/resolve.rs, which the second commit switched to repo.set_config("worktrunk.worktree-path", …). After this PR the function in src/config/user/mutation.rs:134 is only referenced by its own tests (test_set_project_worktree_path and test_set_project_worktree_path_noop_when_unchanged in src/config/user/tests.rs). Per CLAUDE.md ("Don't suppress warnings — delete the code"), this should go in this PR — both mutation.rs:131-148 and the two test functions. Reading the user config still works via load → parse, so removing the setter doesn't affect the per-remote scope as a read source.
2. format_toml used for a shell command (src/commands/worktree/resolve.rs:276-281):
eprintln!(
"{}",
format_toml(&format!(
"git config worktrunk.worktree-path \"{BARE_REPO_WORKTREE_PATH}\""
))
);format_toml is the TOML syntax highlighter (synoptic with the TOML extension); git config <key> <value> is a shell command. With colour enabled, the quoted template lights up as a TOML string while the rest is dimmed as identifiers — fine in NO_COLOR snapshots but mismatched in the real terminal. The corresponding helper for this is format_bash_with_gutter, already used for shell commands in src/git/error.rs:980 and src/output/shell_integration.rs:361. Swapping it here also needs the import (src/commands/worktree/resolve.rs:14-16) updated to bring format_bash_with_gutter in (and drop format_toml if no longer used, though it still is for the accepted-message / preview blocks at lines 302 and 332 which legitimately render TOML-shaped key = "value" lines).
Marking as comment rather than approve since GitHub blocks self-approval.
…highlighting `set_project_worktree_path` lost its sole production caller when `offer_bare_repo_worktree_path_fix` switched to writing `worktrunk.worktree-path` to git config — remove the setter and its two tests. Reading the per-remote scope still works via load → parse. Use `format_bash_with_gutter` instead of `format_toml` for the `git config worktrunk.worktree-path "…"` snippet shown in the non-interactive warning — it's a shell command, not a TOML fragment. The TOML-shaped `worktrunk.worktree-path = "…"` preview/accepted messages keep `format_toml`. Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Pushed a86d15e43 addressing both findings:
|
|
this splits the way configs work for a benefit that seems extremely marginal, unless I'm misunderstanding if folks can describe why they would use this, happy to reopen (hope this is reasonable) |
Problem
The bare-repo
worktree-pathprompt and the user-config resolution chain treat all clones of the same repo as equivalent.When
wt switchdetects a bare repo at a hidden path (.git,.bare) and the default template would produce broken paths likemyproject/.git.main, accepting the prompt currently writes:The
[projects."..."]key is derived from the remote URL, so it matches every local clone of that repository. A user with both a bare clone (myproject/.git) and a regular clone of the same repo has the worktree-path template silently changed for the regular clone too, breaking its layout.The correct scope for "this specific clone" is the repo's git config (
.git/config), which is already used by worktrunk for other per-clone state (worktrunk.default-branch,worktrunk.skip-bare-repo-prompt, etc.).Solution
1. Add
worktrunk.worktree-pathgit-config keySwitch
offer_bare_repo_worktree_path_fixto writeworktrunk.worktree-pathto the repo's git config instead of the user-config per-project stanza. Stored in.git/config, scoped to this clone only.Make the prompt idempotent: if
worktrunk.worktree-pathis already set in git config, skip the prompt entirely.The non-interactive warning and success message become:
2. Thread
worktrunk.worktree-pathinto the resolution chainformat_pathinUserConfignow checks sources in priority order:WORKTRUNK_WORKTREE_PATHenv varworktrunk.worktree-pathin git config[projects."..."].worktree-pathin user configworktree-pathin user configThe env var is checked explicitly (not just via the overlay mechanism) so it correctly wins over a git config value when both are set.
3. Suppress the trailing hint when git config is set
maybe_print_worktree_path_hint(the "To customize worktree locations, runwt config create" hint) now also checksworktrunk.worktree-pathin git config, so the user doesn't see contradictory advice after the prompt just set it.4. Document the three scopes
docs/content/config.md,wt config create --help, and the dev-config example get a new "Scope options" section showing the per-clone / per-remote / global table. The tips & patterns bare-repo section is updated to lead with the git-config approach and explain why multi-clone setups prefer it.Note on scope
This PR is the more invasive half of the original #2951. @max-sixty asked to split it out for separate review since it adds a new exception in the config-resolution chain.
Stacked on #2951 — the diff here will become smaller once #2951 lands.
Testing
test_bare_repo_worktree_path_prompt_skipped_when_git_config_already_set— new test confirming the prompt skips when git config already has the key.test_bare_repo_worktree_path_prompt_auto_accept/..._non_interactive_warning/ the three PTY prompt snapshots — updated to show the git-config write/command.test_docs_are_in_syncpasses.Co-authored with @ammachado from the original PR.