Skip to content

Fix linter in git worktrees#10547

Merged
yyforyongyu merged 1 commit intolightningnetwork:masterfrom
gijswijs:fix-linter-for-worktrees
Feb 4, 2026
Merged

Fix linter in git worktrees#10547
yyforyongyu merged 1 commit intolightningnetwork:masterfrom
gijswijs:fix-linter-for-worktrees

Conversation

@gijswijs
Copy link
Collaborator

@gijswijs gijswijs commented Feb 3, 2026

Summary

  • Fix make lint failing to filter existing issues when run from a
    git worktree
  • Mount the main git directory in Docker when running from a
    worktree

Problem

When running make lint in a git worktree, the linter reports thousands of false positives. This happens because:

  1. The .golangci.yml config uses new-from-rev: 03eab4db... to only show newly introduced issues
  2. This relies on revgrep accessing git history to compute the diff
  3. In a worktree, .git is a file (not a directory) containing a pointer like gitdir: /path/to/main/.git/worktrees/branch-name
  4. The Docker container only mounts the worktree directory (-v $(pwd):/build), not the main .git directory
  5. revgrep can't find the git repository and the diff filter fails silently, causing all ~32k existing issues to be reported

The 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-dir to get the path to the main git directory . If this is not .git we know we are in a worktree. We set the common directory path and mount it into the Docker container. This allows revgrep to 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

  • Run make lint in a git worktree - should pass with 0 issues, or exactly the same amount of issues compared to when not working in a git worktree
  • Run make lint in the main repo - should still work as before
  • Verify the docker command includes -v /path/to/.git:/path/to/.git when in a worktree

@gemini-code-assist
Copy link

Summary of Changes

Hello @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 make lint command from functioning correctly within git worktrees. The problem stemmed from the linter's inability to access the full git history when operating inside a Docker container that only mounted the worktree's directory. The implemented solution intelligently detects worktree environments and ensures the main git repository is also mounted, thereby restoring the linter's intended behavior of filtering issues based on recent changes.

Highlights

  • Linter Fix for Git Worktrees: Addresses an issue where make lint would fail to correctly filter existing issues when run from a git worktree, reporting thousands of false positives.
  • Docker Volume Mounting: Implements a solution to detect git worktrees and conditionally mount the main git directory into the Docker container, allowing the linter's diff processor to access git history.

🧠 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
  • Makefile
    • Added logic to detect if the current execution environment is a git worktree by checking if .git is a file.
    • If a worktree is detected, the path to the main git directory is extracted.
    • A new Docker volume mount (-v $(GIT_WORKTREE_PARENT):$(GIT_WORKTREE_PARENT)) is conditionally added to the DOCKER_TOOLS command to ensure the main git repository is accessible within the container.
Activity
  • No human activity (comments, reviews) 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[bot]

This comment was marked as resolved.

@saubyk saubyk requested review from ellemouton and starius February 3, 2026 17:57
@gijswijs gijswijs force-pushed the fix-linter-for-worktrees branch from 82321ea to ba90d34 Compare February 3, 2026 18:07
@gijswijs gijswijs force-pushed the fix-linter-for-worktrees branch from ba90d34 to 19b9862 Compare February 3, 2026 18:28
@gijswijs gijswijs requested a review from starius February 3, 2026 18:31
Copy link
Collaborator

@starius starius left a comment

Choose a reason for hiding this comment

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

LGTM! 🏆
One note on narrowing the scope of the change to make lint only, not to all dockerized targets.

@gijswijs gijswijs force-pushed the fix-linter-for-worktrees branch from 19b9862 to 47f5a86 Compare February 3, 2026 18:44
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.
@gijswijs gijswijs force-pushed the fix-linter-for-worktrees branch from 47f5a86 to 2643988 Compare February 3, 2026 18:46
@yyforyongyu yyforyongyu merged commit eaa7bcf into lightningnetwork:master Feb 4, 2026
114 of 118 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants