One function

rule_from_pattern in mherrmann/gitignore_parser

The author described this change as Fix patterns with leading exclamation marks (#54). It counts as a record because the check below fails on the code as it stood at d45a08589 and passes on 1040aa547, with nothing else changed between the two runs.

Fix saved2023-10-03
Sharing licenceMIT · LICENSE
Change size+3 2

What the code was meant to do, written into the code itself as a docstring

Take a .gitignore match pattern, such as "*.py[cod]" or "**/*.bak", and return an IgnoreRule suitable for matching against files and directories. Patterns which do not match files, such as comments and blank lines, will return None. Because git allows for nested .gitignore files, a base_path value is required for correct behavior. The base path should be absolute.

The change

5050 pattern = pattern[1:]
5151 if pattern[-1] == '/':
5252 pattern = pattern[:-1]
53- # patterns with leading hashes are escaped with a backslash in front, unescape it
54- if pattern[0] == '\\' and pattern[1] == '#':
53+ # patterns with leading hashes or exclamation marks are escaped with a
54+ # backslash in front, unescape it
55+ if pattern[0] == '\\' and pattern[1] in ('#', '!'):
5556 pattern = pattern[1:]
5657 # trailing spaces are ignored unless they are escaped with a backslash
5758 i = len(pattern)-1

The check that tells the two apart

failpass·tests.py::Test::test_literal_exclamation_mark

Check file tests.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before itd45a0858926f8db2fe627fea9e99d794d264dabf
Broken version dated2023-10-03
Modulegitignore_parser
Units changedrule_from_pattern
Fingerprint0c0bd906f07400ce
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in mherrmann/gitignore_parser