Skip to content

Fix #20958: Support .git/info/exclude for --exclude-gitignore#21286

Open
RogerJinIS wants to merge 2 commits intopython:masterfrom
RogerJinIS:20958/git-info-exclude
Open

Fix #20958: Support .git/info/exclude for --exclude-gitignore#21286
RogerJinIS wants to merge 2 commits intopython:masterfrom
RogerJinIS:20958/git-info-exclude

Conversation

@RogerJinIS
Copy link
Copy Markdown

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:
IMG_7911

All cmdline.test passing:
IMG_3176

@github-actions
Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

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.

exclude-gitignore does not read .git/info/exclude

2 participants