Skip to content

fix: detect linked git worktrees when locating source-control root#18

Merged
philasmar merged 9 commits into
philasmar:devfrom
GarrettBeatty:gcbeatty/git-worktree-support
May 21, 2026
Merged

fix: detect linked git worktrees when locating source-control root#18
philasmar merged 9 commits into
philasmar:devfrom
GarrettBeatty:gcbeatty/git-worktree-support

Conversation

@GarrettBeatty
Copy link
Copy Markdown
Contributor

Summary

  • In a linked git worktree, .git is a file containing a gitdir: pointer rather than a directory. GitHandler.FindGitRootDirectory only checked for .git as a directory, so it walked past the worktree and resolved to the main repository — change files were written into the wrong repo and other commands operated on the wrong tree.
  • Treat a .git file as a valid root marker alongside a .git directory. LibGit2Sharp already resolves worktree paths natively in new Repository(path), so no other code paths required changes.

Repro

git clone <some-repo-using-autover>
cd <some-repo-using-autover>
git worktree add ../wt feature/foo
cd ../wt
autover change --project-name SomeProject -m "msg"   # exits 0; file written into the parent clone, not ../wt

Test plan

  • New regression test GitWorktreeTest.ChangeCommand_FromLinkedWorktree_WritesChangeFileInsideWorktree creates a real linked worktree via git worktree add and asserts autover change writes inside the worktree and not in the main repository.
  • Verified the new test fails on the unpatched code and passes with the fix.
  • All 18 tests pass on the fix branch.

philasmar and others added 9 commits March 22, 2024 16:35
ci: improve release process using GitHub workflows
In a linked git worktree, `.git` is a file containing a `gitdir:`
pointer rather than a directory. The previous root lookup only looked
for `.git` as a directory, so it walked past the worktree and resolved
to the main repository's root, causing change files to be written into
the wrong repo and other commands to operate on the wrong tree.

Treat a `.git` file as a valid root marker alongside a `.git` directory.
LibGit2Sharp already handles worktree paths natively when constructing
`new Repository(...)`, so no other code paths need to change.

Adds a regression test that creates a real linked worktree with
`git worktree add` and asserts that `autover change` writes inside the
worktree, not the main repository.
@philasmar philasmar merged commit 78d0842 into philasmar:dev May 21, 2026
1 check passed
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