Skip to content

Commit

Permalink
pathspec-based version. #24 cpburnz/python-pathspec#38
Browse files Browse the repository at this point in the history
  • Loading branch information
excitoon committed Aug 28, 2022
1 parent cfa6678 commit df86407
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 6 additions & 3 deletions gitignorefile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import os
import re

import pathspec


def parse(path, base_path=None):
if base_path is None:
Expand Down Expand Up @@ -41,8 +43,9 @@ def __call__(self, path, is_dir=None):

parent_gitignore = parent.join(".gitignore")
if parent_gitignore.isfile():
matches = parse(str(parent_gitignore), base_path=parent)
add_to_children[parent] = (matches, plain_paths)
with open(str(parent_gitignore)) as f:
matches = pathspec.PathSpec.from_lines("gitwildmatch", f)
add_to_children[parent] = ((matches, parent), plain_paths)
plain_paths = []

else:
Expand Down Expand Up @@ -74,7 +77,7 @@ def __call__(self, path, is_dir=None):
for plain_path in plain_paths:
self.__gitignores[plain_path.parts] = self.__gitignores[parent.parts]

return any((m(path, is_dir=is_dir) for m in self.__gitignores[parent.parts]))
return any((m[0].match_file(path.relpath(m[1])) for m in self.__gitignores[parent.parts]))


class _Path:
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pathspec

0 comments on commit df86407

Please sign in to comment.