Skip to content

Fix negated root-only gitignore patterns - #180

Merged
cpburnz merged 4 commits into
cpburnz:masterfrom
lexingtonhibiki:fix/negated-root-pattern-20261102
Nov 8, 2026
Merged

cpburnz merged 4 commits into
cpburnz:masterfrom
lexingtonhibiki:fix/negated-root-pattern-20261102

Conversation

@lexingtonhibiki

Copy link
Copy Markdown
Contributor

Summary

Treat !/ as a no-op, matching Git and the existing treatment of /.
The root-only check currently runs before removing !, so !/ instead compiles to a directory negation. With ['*', '!/', '!a/keep.txt'], that incorrectly reopens a/ and permits a/keep.txt. A real Git repository keeps the file ignored; both git check-ignore and the index after git add -A confirm it.

Move the root-only no-op check after negation processing. Leave GitIgnoreBasicPattern unchanged because its / behavior is intentionally different.

Regression coverage

  • Text and byte patterns, trailing spaces/CRLF, all error policies.
  • All existing Simple/RE2/Hyperscan test configurations.
  • Controls for /, !//, empty/comment patterns, actual !a/ reinclusion and escaped \!/.
  • Original source fails 48 regression subcases; patched source passes all four new test methods.

Validation

On Linux, CPython 3.12.14:

  • Full project unittest suite: 299 tests, OK, one existing skip, both optional engines installed.
  • Real Git 2.52.0 index oracle: 180 comparisons across 12 small rule sets, five actual files and three backends; all pass.
  • Strict Sphinx HTML build passes.
  • Wheel and sdist build passes; patch applies cleanly to the original source and git diff --check passes.
  • Project-scoped mypy and Pyright are not clean: respectively five and eight existing diagnostics, identical before and after this patch.

This is a minimal reproducible correctness bug, not a claim of an observed production incident or its prevalence. Python 3.13.5 also ran the suite successfully, but without the optional backends (844 subtest skips). Other operating systems and upstream CI have not been verified here.

AI assistance disclosure: Codex performed the investigation, patch, tests and draft preparation, with independent automated verification of the Git reproduction, focused tests and full unittest suite. No human code review is claimed.

@cpburnz

cpburnz commented Nov 8, 2026

Copy link
Copy Markdown
Owner

Thanks for finding and fixing this!

@cpburnz
cpburnz marked this pull request as ready for review November 8, 2026 00:33
@cpburnz
cpburnz merged commit 9b25ad3 into cpburnz:master Nov 8, 2026
cpburnz added a commit that referenced this pull request Nov 8, 2026
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.

2 participants