Skip to content

Fix bump not working in git worktrees#84

Open
andypost wants to merge 4 commits into
mainfrom
worktree-fix
Open

Fix bump not working in git worktrees#84
andypost wants to merge 4 commits into
mainfrom
worktree-fix

Conversation

@andypost

@andypost andypost commented Feb 8, 2026

Copy link
Copy Markdown

In a git worktree, .git is a file (not a directory) pointing to the main repository's .git/worktrees// directory. go-git's PlainOpen() uses EnableDotGitCommonDir: false by default, which means it does not read the commondir file to discover shared data (objects, refs). This causes operations like CommitObject() and Log() to fail because the objects database is not found in the worktree-specific directory.

Replace git.PlainOpen() with git.PlainOpenWithOptions() using EnableDotGitCommonDir: true in all four locations:

  • pkg/repository/git.go: NewBumper()
  • actionSync.resources.go: findResourcesChangeTime(), processResource()
  • actionSync.variables.go: findVariableUpdateTime()

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 NewBumper() and PlainOpenWithOptions work correctly on both regular repositories and git worktrees.

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @andypost, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical bug affecting git operations within worktree environments by updating the go-git library calls. By explicitly enabling the EnableDotGitCommonDir option, the system can now correctly interact with shared git objects and references, which was previously causing failures in operations like CommitObject() and Log(). The changes are carefully implemented to maintain compatibility with standard repositories and are thoroughly tested to ensure robustness.

Highlights

  • Worktree Compatibility Fix: Corrected an issue where go-git operations failed in git worktrees due to the default EnableDotGitCommonDir: false setting, which prevented proper access to shared git data like objects and refs.
  • API Update for Git Operations: Replaced git.PlainOpen() with git.PlainOpenWithOptions() and explicitly set EnableDotGitCommonDir: true in four key locations (NewBumper, findResourcesChangeTime, processResource, findVariableUpdateTime) to ensure correct repository handling in worktree environments.
  • Backward Compatibility and Safety: The change to enable EnableDotGitCommonDir is safe for standard repositories, as the go-git library gracefully falls back to normal behavior when the common directory file does not exist.
  • Comprehensive Testing: New test cases have been introduced to validate the correct functionality of NewBumper() and PlainOpenWithOptions() for both regular git repositories and git worktrees, ensuring the fix is robust.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • actionSync.resources.go
    • Updated git.PlainOpen calls to git.PlainOpenWithOptions with EnableDotGitCommonDir: true in findResourcesChangeTime and processResource functions.
  • actionSync.variables.go
    • Modified the findVariableUpdateTime function to use git.PlainOpenWithOptions with EnableDotGitCommonDir: true instead of git.PlainOpen.
  • pkg/repository/git.go
    • Changed the NewBumper function to initialize the git repository using git.PlainOpenWithOptions with EnableDotGitCommonDir: true.
  • pkg/repository/git_test.go
    • Added a new test file containing helper functions (initTestRepo, createWorktree) to set up test repositories and worktrees.
    • Introduced new tests (TestNewBumper, TestNewBumperWorktree, TestPlainOpenWithOptionsRegularRepo, TestPlainOpenWithOptionsWorktree) to verify worktree compatibility and PlainOpenWithOptions behavior.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly fixes an issue with git worktrees by using git.PlainOpenWithOptions with EnableDotGitCommonDir: true. The changes are applied consistently, and new tests have been added to cover both regular repositories and worktrees, which is great.

I've left a few comments with suggestions to improve efficiency by avoiding opening the same git repository multiple times within loops. I've also pointed out a minor issue in the new tests where an error is not being checked. Addressing these points will make the code more robust and performant.

Comment thread actionSync.resources.go Outdated

func (s *syncAction) processResource(resource *sync.Resource, commitsGroups *sync.OrderedMap[*CommitsGroup], commitsMap map[string]map[string]string, _ *git.Repository, gitPath string, mx *async.Mutex) error {
repo, err := git.PlainOpen(gitPath)
repo, err := git.PlainOpenWithOptions(gitPath, &git.PlainOpenOptions{EnableDotGitCommonDir: true})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This repository is opened on every call to processResource, which is inefficient as it's called within a loop. The calling function findResourcesChangeTime already opens the repository and passes it to this function (as an ignored parameter _).

You can improve performance by using the passed-in repository object. To do this:

  1. Change the function signature on line 298 to name the *git.Repository parameter (e.g., repo) and remove the gitPath parameter.
    func (s *syncAction) processResource(resource *sync.Resource, commitsGroups *sync.OrderedMap[*CommitsGroup], commitsMap map[string]map[string]string, repo *git.Repository, mx *async.Mutex) error {
  2. Remove lines 299-302 where the repository is re-opened.
  3. Update the call site in findResourcesChangeTime at line 253 accordingly.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed review again

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gemini-code-assist review again

/gemini review

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for addressing the feedback! I've reviewed the changes in actionSync.resources.go and confirm that the processResource function now correctly reuses the git.Repository object passed from findResourcesChangeTime, eliminating the redundant git.PlainOpen call within the loop. This improves efficiency as suggested.

Great work!

Comment thread actionSync.variables.go Outdated
Comment thread pkg/repository/git_test.go Outdated
andypost and others added 2 commits February 8, 2026 08:03
In a git worktree, .git is a file (not a directory) pointing to the
main repository's .git/worktrees/<name>/ directory. go-git's
PlainOpen() uses EnableDotGitCommonDir: false by default, which means
it does not read the commondir file to discover shared data (objects,
refs). This causes operations like CommitObject() and Log() to fail
because the objects database is not found in the worktree-specific
directory.

Replace git.PlainOpen() with git.PlainOpenWithOptions() using
EnableDotGitCommonDir: true in all four locations:
- pkg/repository/git.go: NewBumper()
- actionSync.resources.go: findResourcesChangeTime(), processResource()
- actionSync.variables.go: findVariableUpdateTime()

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 NewBumper() and PlainOpenWithOptions work correctly
on both regular repositories and git worktrees.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
andypost and others added 2 commits February 8, 2026 08:10
Reuse git.Repository in processResource instead of reopening on each
call. Check ForEach errors in tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move PlainOpenWithOptions call from findVariableUpdateTime (called per
vars file from worker goroutines) to populateTimelineVars (called once
before spawning workers). Pass *git.Repository instead of gitPath.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

3 participants