Skip to content

Fix compose not working in git worktrees#71

Open
andypost wants to merge 1 commit intolaunchrctl:mainfrom
andypost:worktree-support
Open

Fix compose not working in git worktrees#71
andypost wants to merge 1 commit intolaunchrctl:mainfrom
andypost:worktree-support

Conversation

@andypost
Copy link

@andypost andypost commented Feb 8, 2026

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:

  • 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.

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>
@andypost
Copy link
Author

andypost commented Feb 8, 2026

@jbguerraz @lexbritvin looking for review

@andypost
Copy link
Author

andypost commented Feb 8, 2026

related fix skilld-labs/plasmactl-bump#84

@andypost
Copy link
Author

andypost commented Feb 8, 2026

@gemini-code-assist review it

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

Comments