Skip to content

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

Merged
ilevkivskyi merged 2 commits intopython:masterfrom
RogerJinIS:20958/git-info-exclude
Apr 22, 2026
Merged

Fix #20958: Support .git/info/exclude for --exclude-gitignore#21286
ilevkivskyi merged 2 commits intopython:masterfrom
RogerJinIS:20958/git-info-exclude

Conversation

@RogerJinIS
Copy link
Copy Markdown
Contributor

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. ✅

Copy link
Copy Markdown
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

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

LG, thanks!

@ilevkivskyi ilevkivskyi merged commit 3bf45e6 into python:master Apr 22, 2026
24 checks passed
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

3 participants