fix: resolve worktree path from ProjectRoot, not WorkDir (#174)#218
Merged
fix: resolve worktree path from ProjectRoot, not WorkDir (#174)#218
Conversation
When sidecar is started from a git repo subfolder, WorkDir is set to that subfolder (e.g. /repos/myrepo/subfolder). Both doCreateWorktree and fetchAndCreateWorktree were computing the new worktree's parent directory as filepath.Dir(WorkDir), which resolves to the git root itself — placing the new worktree *inside* the main repo instead of beside it. Fix: use ProjectRoot (already correctly resolved to the main worktree path via GetMainWorktreePath) instead. When ProjectRoot is empty fall back to WorkDir for safety. Adds a regression test documenting the path-computation invariant. Fixes #174
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.
Problem
When sidecar is started from a subfolder of a git repo (e.g.
cd myrepo/src && sidecar),WorkDiris set to that subfolder. BothdoCreateWorktree(worktree.go) andfetchAndCreateWorktree(fetch_pr.go) computed the new worktree's parent asfilepath.Dir(WorkDir), which resolves to the git root itself — placing the new worktree inside the main repo instead of beside it.This caused
git worktree addto fail withfatal: invalid reference: <branch>: exit status 128because the path conflicted with existing repo contents.Fix
Use
ProjectRoot(already correctly resolved to the main worktree path viaGetMainWorktreePathin main.go) as the anchor for the parent-dir calculation. Falls back toWorkDirifProjectRootis empty.Before (broken when started from subfolder):
After (fixed):
Testing
go test ./...)TestWorktreePathResolvesFromProjectRootregression testFixes #174