Fix #20958: Support .git/info/exclude for --exclude-gitignore#21286
Open
RogerJinIS wants to merge 2 commits intopython:masterfrom
Open
Fix #20958: Support .git/info/exclude for --exclude-gitignore#21286RogerJinIS wants to merge 2 commits intopython:masterfrom
RogerJinIS wants to merge 2 commits intopython:masterfrom
Conversation
Contributor
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #20958.
--exclude-gitignore now respects patterns in .git/info/exclude, not just .gitignore files. Previously, mypy ignored .git/info/exclude entirely, causing files matched by those patterns to still be checked.
Changes
File: mypy/modulefinder.py — find_gitignores()
File: test-data/unit/cmdline.test
Added handling for .git/info/exclude inside the git root detection branch. When find_gitignores identifies a directory as a git root (i.e. it contains a .git folder), it now also checks for .git/info/exclude. If the file exists, it is parsed with PathSpec.from_lines("gitignore", ...) and included in the returned list of gitignore specs, alongside any .gitignore found in the same directory. Parse errors are printed to stderr and the file is skipped, matching the existing behavior for malformed .gitignore files.
Testing
Added testCmdlineExcludeGitignoreWithGitInfoExclude to test-data/unit/cmdline.test to verify that patterns in .git/info/exclude are respected when using --exclude-gitignore.
To run the new test:
Install dependencies:
bashpip install -r test-requirements.txt
pip install -e .
Run the test:
bashpytest -n0 -k testCmdlineExcludeGitignoreWithGitInfoExclude
Or with full node ID:
bashpytest -n0 mypy/test/testcmdline.py::PythonCmdlineSuite::cmdline.test::testCmdlineExcludeGitignoreWithGitInfoExclude
Photo evidence of tests passing locally:
Specific test for this issue:

All cmdline.test passing:
