Fix compose not working in git worktrees#71
Open
andypost wants to merge 1 commit intolaunchrctl:mainfrom
Open
Conversation
In a git worktree, .git is a file (not a directory) pointing to the main repository's .git/worktrees/<name>/ directory. The worktree-specific git dir only contains HEAD and a commondir file, while shared data (objects, refs, config, packed-refs) lives in the main .git directory. go-git's PlainOpen() uses EnableDotGitCommonDir: false by default, which means it follows the .git file to the worktree dir but does not read the commondir file to discover shared data. This causes operations like CommitObject() to fail because the objects database is not found in the worktree-specific directory. Replace git.PlainOpen() with git.PlainOpenWithOptions() using EnableDotGitCommonDir: true in both affected locations: - compose/builder.go: getVersionedMap() - used to determine versioned files when --skip-not-versioned is set. Without the fix, the error is silently caught and the flag has no effect in worktrees. - compose/git.go: EnsureLatest() - used to check if downloaded packages are up to date. Changed for consistency and robustness. EnableDotGitCommonDir: true is safe for non-worktree repos: the commondir file won't exist, so go-git falls through to normal behavior. Add tests verifying getVersionedMap() and PlainOpenWithOptions work correctly on both regular repositories and git worktrees. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Author
|
@jbguerraz @lexbritvin looking for review |
Author
|
related fix skilld-labs/plasmactl-bump#84 |
Author
|
@gemini-code-assist review it |
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.
In a git worktree, .git is a file (not a directory) pointing to the main repository's .git/worktrees// directory. The worktree-specific git dir only contains HEAD and a commondir file, while shared data (objects, refs, config, packed-refs) lives in the main .git directory.
go-git's PlainOpen() uses EnableDotGitCommonDir: false by default, which means it follows the .git file to the worktree dir but does not read the commondir file to discover shared data. This causes operations like CommitObject() to fail because the objects database is not found in the worktree-specific directory.
Replace git.PlainOpen() with git.PlainOpenWithOptions() using EnableDotGitCommonDir: true in both affected locations:
EnableDotGitCommonDir: true is safe for non-worktree repos: the commondir file won't exist, so go-git falls through to normal behavior.
Add tests verifying getVersionedMap() and PlainOpenWithOptions work correctly on both regular repositories and git worktrees.