Whole file

mherrmann/gitignore_parser

The author described this change as Fix: do not resolve symlinks. It counts as a record because the check below fails on the code as it stood at 37ecfd558 and passes on 721f804b0, with nothing else changed between the two runs.

Fix saved2023-10-05
Sharing licenceMIT · LICENSE
Change size+14 4

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

Fix: do not resolve symlinks

The change

22 import os
33 import re
44
5-from os.path import dirname
5+from os.path import abspath, dirname
66 from pathlib import Path
77 from typing import Reversible, Union
88
102102 negation=negation,
103103 directory_only=directory_only,
104104 anchored=anchored,
105- base_path=Path(base_path) if base_path else None,
105+ base_path=_normalize_path(base_path) if base_path else None,
106106 source=source
107107 )
108108
125125 def match(self, abs_path: Union[str, Path]):
126126 matched = False
127127 if self.base_path:
128- rel_path = str(Path(abs_path).resolve().relative_to(self.base_path))
128+ rel_path = str(_normalize_path(abs_path).relative_to(self.base_path))
129129 else:
130- rel_path = str(Path(abs_path))
130+ rel_path = str(_normalize_path(abs_path))
131131 # Path() strips the trailing slash, so we need to preserve it
132132 # in case of directory-only negation
133133 if self.negation and type(abs_path) == str and abs_path[-1] == '/':
208208 else:
209209 res.append('($|\\/)')
210210 return ''.join(res)
211+
212+
213+def _normalize_path(path: Union[str, Path]) -> Path:
214+ """Normalize a path without resolving symlinks.
215+
216+ This is equivalent to `Path.resolve()` except that it does not resolve symlinks.
217+ Note that this simplifies paths by removing double slashes, `..`, `.` etc. like
218+ `Path.resolve()` does.
219+ """
220+ return Path(abspath(path))
211221

The check that tells the two apart

failpass·tests.py::Test::test_symlink_to_another_directory

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 it37ecfd558c4baf573f9df1efc61d5c3414b38764
Broken version dated2023-10-04
Modulegitignore_parser
Units changedIgnoreRule, rule_from_pattern
Fingerprint151d27d7ec60dc4b
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