From 6bc1c1d05a509cf222cef8ae1bfc2c2bf2b8e42a Mon Sep 17 00:00:00 2001 From: cpburnz <2126043+cpburnz@users.noreply.github.com> Date: Sat, 25 Feb 2023 20:33:07 -0500 Subject: [PATCH] Address 74 --- CHANGES.rst | 14 ++++++++++++++ pathspec/_meta.py | 1 + pathspec/gitignore.py | 5 ++++- tests/test_gitignore.py | 30 ++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 103344a..509cf90 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -3,6 +3,20 @@ Change History ============== +0.11.1 (TBD) +------------ + +Improvements: + +- `Issue #74`_: Include directory should override exclude file. +- `Pull #75`_: Fix partially unknown PathLike type. +- Convert `os.PathLike` to a string properly using `os.fspath`. + +.. _`Issue #74`: https://github.com/cpburnz/python-pathspec/issues/74 +.. _`Pull #75`: https://github.com/cpburnz/python-pathspec/pull/75 + + + 0.11.0 (2023-01-24) ------------------- diff --git a/pathspec/_meta.py b/pathspec/_meta.py index 496afba..b368db7 100644 --- a/pathspec/_meta.py +++ b/pathspec/_meta.py @@ -49,6 +49,7 @@ "haimat ", "Avasam ", "yschroeder ", + "axesider ", ] __license__ = "MPL 2.0" __version__ = "0.11.1.dev1" diff --git a/pathspec/gitignore.py b/pathspec/gitignore.py index 0c3481c..a939225 100644 --- a/pathspec/gitignore.py +++ b/pathspec/gitignore.py @@ -128,7 +128,10 @@ def _match_file( # Pattern matched by a file pattern. priority = 2 - if priority >= out_priority: + if pattern.include and dir_mark: + out_matched = pattern.include + out_priority = priority + elif priority >= out_priority: out_matched = pattern.include out_priority = priority diff --git a/tests/test_gitignore.py b/tests/test_gitignore.py index 7d261ec..abb5b6a 100644 --- a/tests/test_gitignore.py +++ b/tests/test_gitignore.py @@ -358,3 +358,33 @@ def test_06_issue_64(self): } ignores = set(spec.match_files(files)) self.assertEqual(ignores, files) + + def test_07_issue_74(self): + """ + Test include directory should override exclude file. + """ + spec = GitIgnoreSpec.from_lines([ + '*', # Ignore all files by default + '!*/', # but scan all directories + '!*.txt', # Text files + '/test1/**', # ignore all in the directory + ]) + files = { + 'test1/b.bin', + 'test1/a.txt', + 'test1/c/c.txt', + 'test2/a.txt', + 'test2/b.bin', + 'test2/c/c.txt', + } + ignores = set(spec.match_files(files)) + self.assertEqual(ignores, { + 'test1/b.bin', + 'test1/a.txt', + 'test1/c/c.txt', + 'test2/b.bin', + }) + self.assertEqual(files - ignores, { + 'test2/a.txt', + 'test2/c/c.txt', + })