Skip to content

Fix worktree auto-discovery on git 2.52+#27

Open
bkildow wants to merge 1 commit intomainfrom
fix/git-2.52-worktree-config
Open

Fix worktree auto-discovery on git 2.52+#27
bkildow wants to merge 1 commit intomainfrom
fix/git-2.52-worktree-config

Conversation

@bkildow
Copy link
Copy Markdown
Owner

@bkildow bkildow commented May 8, 2026

Summary

  • Git 2.52 tightened bare+linked-worktree handling: when the common dir has core.bare=true and extensions.worktreeConfig=true, every linked worktree must override core.bare=false in its own config.worktree. Without it, git status (and everything that auto-discovers) fails from inside a worktree.
  • wt clone now enables extensions.worktreeConfig once, and WorktreeAdd/WorktreeAddNew write core.bare=false into each new worktree's config.worktree (with the extension call cached per Runner so we don't re-fork).
  • New wt repair command back-fills the extension and per-worktree override on projects cloned before this fix. Idempotent.

Test plan

  • make dev (fmt, lint, full test suite, build) clean
  • TestIntegrationCloneAndWorktree extended to assert extensions.worktreeConfig=true on the bare config, core.bare=false in the worktree's config.worktree, and that git status succeeds from inside the worktree
  • New TestHasBareFalse covers the tolerant config parser
  • New TestWorktreeConfigPath_LinkedWorktree resolves a real .git pointer file against a real bare repo + linked worktree
  • Manual: run ./wt repair against an existing project on git 2.52+ and confirm git status works in each worktree afterward; second run reports 0 repaired

Git 2.52 refuses to auto-discover from a linked worktree when the bare
common dir has core.bare=true and extensions.worktreeConfig=true unless
each worktree's config.worktree explicitly sets core.bare=false. wt's
layout hits this exactly, so every git command from inside a worktree
fails (e.g. "git status").

- Enable extensions.worktreeConfig on the bare repo during wt clone, and
  cache the call on Runner so it isn't re-forked on every wt add.
- Write core.bare=false into each worktree's config.worktree after every
  WorktreeAdd / WorktreeAddNew.
- Add wt repair as an idempotent migration for projects cloned before
  this fix: enables the extension and back-fills config.worktree on every
  linked worktree that lacks the override.
- Cover the regression in TestIntegrationCloneAndWorktree (git status
  from inside the worktree must succeed) and add unit tests for the
  config parser and gitdir-pointer resolution.
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.

1 participant