Fix bump not working in git worktrees#84
Conversation
Summary of ChangesHello @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 Highlights
🧠 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
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
|
|
||
| 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}) |
There was a problem hiding this comment.
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:
- Change the function signature on line 298 to name the
*git.Repositoryparameter (e.g.,repo) and remove thegitPathparameter.func (s *syncAction) processResource(resource *sync.Resource, commitsGroups *sync.OrderedMap[*CommitsGroup], commitsMap map[string]map[string]string, repo *git.Repository, mx *async.Mutex) error {
- Remove lines 299-302 where the repository is re-opened.
- Update the call site in
findResourcesChangeTimeat line 253 accordingly.
There was a problem hiding this comment.
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!
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>
137218e to
726eb4f
Compare
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>
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:
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.