Skip to content

Commit

Permalink
refractor
Browse files Browse the repository at this point in the history
  • Loading branch information
bitranox committed Sep 18, 2020
1 parent 49fc50a commit f3c8a4d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ TODO:
- add nested .gitignore files
- documentation

v2.0.1
--------
2020-09-18:
- correct matching bug in subdirectories
- avoid redundant patterns when match subdirectories

v2.0.0
--------
2020-08-14:
Expand Down
23 changes: 13 additions & 10 deletions igittigitt/igittigitt.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def get_rules_from_git_pattern(
>>> assert get_rules_from_git_pattern('# some comment', some_base_dir) == []
>>> assert get_rules_from_git_pattern(' # some comment', some_base_dir) == []
>>> get_rules_from_git_pattern(r' \\#some_file', some_base_dir)
[IgnoreRule(pattern_fnmatch='.../\\\\#some_file', ...), IgnoreRule(pattern_fnmatch='.../**/\\\\#some_file', ...)]
[IgnoreRule(pattern_fnmatch='.../**/\\\\#some_file', ...)]
>>> # Trailing spaces are ignored unless
>>> # they are quoted with backslash ("\").
Expand All @@ -263,7 +263,7 @@ def get_rules_from_git_pattern(
>>> # but it seems like !
>>> # see: https://stackoverflow.com/questions/10213653
>>> get_rules_from_git_pattern(r'something \\ ', some_base_dir)
[IgnoreRule(pattern_fnmatch='.../something\\\\ ', ...), IgnoreRule(pattern_fnmatch='.../**/something\\\\ ', ...)]
[IgnoreRule(pattern_fnmatch='.../**/something\\\\ ', ...)]
>>> # If there is a separator at the beginning or middle (or both)
>>> # of the pattern, then the pattern is relative to the directory
Expand Down Expand Up @@ -399,24 +399,27 @@ def create_pattern_variations(
>>> path_base = pathlib.Path(__file__).parent.resolve()
>>> create_pattern_variations(pattern='test', path_base_dir=path_base, match_files=True, match_dirs=True, match_also_subdirs=True)
['.../test', '.../test/*', '.../**/test', '.../**/test/*']
['.../**/test', '.../**/test/**/*']
>>> create_pattern_variations(pattern='test', path_base_dir=path_base, match_files=True, match_dirs=True, match_also_subdirs=False)
['.../test', '.../test/**/*']
"""
str_path_base_dir = str(path_base_dir).replace("\\", "/")
l_patterns: List[str] = list()

pattern_match_file = str_path_base_dir + "/" + pattern
if match_files:
l_patterns.append(pattern_match_file)
if match_dirs:
l_patterns.append(pattern_match_file + "/*")

if match_also_subdirs:
pattern_match_file_in_subdirs = str_path_base_dir + "/**/" + pattern
if match_files:
l_patterns.append(pattern_match_file_in_subdirs)
if match_dirs:
l_patterns.append(pattern_match_file_in_subdirs + "/*")
l_patterns.append(pattern_match_file_in_subdirs + "/**/*")
else:
pattern_match_file = str_path_base_dir + "/" + pattern
if match_files:
l_patterns.append(pattern_match_file)
if match_dirs:
l_patterns.append(pattern_match_file + "/**/*")

return l_patterns


Expand Down

0 comments on commit f3c8a4d

Please sign in to comment.