Skip to content

Commit

Permalink
FIx.
Browse files Browse the repository at this point in the history
  • Loading branch information
excitoon committed Aug 28, 2022
1 parent 935977a commit 2729d27
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions gitignorefile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def __init__(self, path):
if isinstance(path, str):
abs_path = os.path.abspath(path)
self.__parts = tuple(_path_split(abs_path))
print(self.__parts)
self.__joined = abs_path
self.__is_dir = None

Expand Down Expand Up @@ -260,9 +259,6 @@ def match(self, rel_path, is_dir):
return match and (not self.__directory_only or match.group(1) is not None or is_dir)


_seps_expr = re.escape(os.sep)
_non_sep_expr = f"[^{re.escape(os.sep)}]"

if os.altsep is not None:
_all_seps_expr = f"[{re.escape(os.sep)}{re.escape(os.altsep)}]"
_path_split = lambda path: re.split(_all_seps_expr, path)
Expand All @@ -280,7 +276,7 @@ def _fnmatch_pathname_to_regexp(pattern, directory_only):
"""
i, n = 0, len(pattern)

res = [f"(?:^|{_seps_expr})"] if pattern else [] # Empty name means no path fragment.
res = ["(?:^|/)"] if pattern else [] # Empty name means no path fragment.
while i < n:
c = pattern[i]
i += 1
Expand All @@ -291,19 +287,16 @@ def _fnmatch_pathname_to_regexp(pattern, directory_only):
res.append(".*")
if pattern[i] == "/":
i += 1
res.append(f"{_seps_expr}?")
res.append("/?")

else:
res.append(f"{_non_sep_expr}*")
res.append(f"[^/]*")

except IndexError:
res.append(f"{_non_sep_expr}*")
res.append(f"[^/]*")

elif c == "?":
res.append(_non_sep_expr)

elif c == "/":
res.append(_seps_expr)
res.append("[^/]")

elif c == "[":
j = i
Expand All @@ -329,9 +322,9 @@ def _fnmatch_pathname_to_regexp(pattern, directory_only):
res.append(re.escape(c))

if directory_only: # In this case we are interested if there is something after slash.
res.append(f"({_seps_expr}.+)?$")
res.append(f"(/.+)?$")

else:
res.append(f"(?:{_seps_expr}|$)")
res.append(f"(?:/|$)")

return "".join(res)

0 comments on commit 2729d27

Please sign in to comment.