Fix linter in git worktrees#10547
Conversation
Summary of ChangesHello @gijswijs, 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 issue preventing 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
|
82321ea to
ba90d34
Compare
ba90d34 to
19b9862
Compare
starius
left a comment
There was a problem hiding this comment.
LGTM! 🏆
One note on narrowing the scope of the change to make lint only, not to all dockerized targets.
19b9862 to
47f5a86
Compare
When running `make lint` in a git worktree, the diff processor fails with "no version control repository found" because the Docker container only mounts the worktree directory, not the main git directory that the worktree's .git file references. This causes golangci-lint's `new-from-rev` filter to not work, resulting in all ~32k existing lint issues being reported instead of only newly introduced ones. Fix by detecting when we're in a worktree (.git is a file, not a directory) and mounting the main .git directory into the container so revgrep can access the git history.
47f5a86 to
2643988
Compare
Summary
make lintfailing to filter existing issues when run from agit worktree
worktree
Problem
When running
make lintin a git worktree, the linter reports thousands of false positives. This happens because:.golangci.ymlconfig usesnew-from-rev: 03eab4db...to only show newly introduced issuesrevgrepaccessing git history to compute the diff.gitis a file (not a directory) containing a pointer likegitdir: /path/to/main/.git/worktrees/branch-name-v $(pwd):/build), not the main.gitdirectoryrevgrepcan't find the git repository and the diff filter fails silently, causing all ~32k existing issues to be reportedThe linter logs show: level=warning msg="[runner] Can't process result by diff processor: can't prepare diff by revgrep: no version control repository found"
Solution
Detect if we're in a git worktree. Use
git rev-parse --git-common-dirto get the path to the main git directory . If this is not.gitwe know we are in a worktree. We set the common directory path and mount it into the Docker container. This allowsrevgrepto access git history and correctly filter issues.The fix is backwards compatible—in a normal (non-worktree) repo, no additional volume is mounted.
Test plan
make lintin a git worktree - should pass with 0 issues, or exactly the same amount of issues compared to when not working in a git worktreemake lintin the main repo - should still work as before-v /path/to/.git:/path/to/.gitwhen in a worktree