Skip to content

Commit

Permalink
support */dir1 pattern on ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
deadc0de6 committed Dec 28, 2023
1 parent 51b62ab commit 55caaf6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ dynvariables:

## Ignore pattern

Officially only `*/file` and `*/dir/*` should be used for ignore pattern.
However we still recursively process each path components to ensure
that pattern like `*/dir` are matched (see `_match_ignore_pattern`
in `utils.py`).

We also append a separator to directory before checking
for a match with the ignore patterns.

**compare**

* for files, match with ignore directly
Expand Down
2 changes: 1 addition & 1 deletion docs/config/config-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ It is possible to ignore specific patterns when using dotdrop.
* Using dotfiles block [upignore](config-dotfiles.md)
* Using the command line switch `-i`/`--ignore`

The ignore pattern must follow Unix shell-style wildcards, like, for example `*/path/to/file` for files or
The ignore pattern must follow Unix shell-style wildcards, like for example `*/path/to/file` for files and
`*/path/to/directory/*` for directories.
Make sure to quote these when using wildcards in the config file.

Expand Down
24 changes: 16 additions & 8 deletions dotdrop/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,23 @@ def strip_home(path):
def _match_ignore_pattern(path, pattern, debug=False):
"""
returns true if path matches the pattern
we test the entire path but also
any parent directory recursively to
be able to match pattern like "*/dir"
"""
if debug:
msg = f'fnmatch \"{path}\" against {pattern}'
LOG.dbg(msg, force=True)
ret = fnmatch.fnmatch(path, pattern)
if debug:
LOG.dbg(f'ignore \"{pattern}\" match: {path}',
force=True)
return ret
subpath = path
while subpath != os.path.sep:
if debug:
msg = f'fnmatch \"{subpath}\" against {pattern}'
LOG.dbg(msg, force=True)
ret = fnmatch.fnmatch(subpath, pattern)
if debug:
LOG.dbg(f'ignore \"{pattern}\" match: {subpath}',
force=True)
if ret:
return ret
subpath = os.path.dirname(subpath)
return False


def _must_ignore(path, ignores, neg_ignores, debug=False):
Expand Down
8 changes: 4 additions & 4 deletions tests-ng/ignore-patterns.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ dotfiles:
src: mpv
dst: ${tmpd}/mpv
cmpignore:
- '*/watch_later/*'
- '*/watch_later'
upignore:
- '*/watch_later/*'
- '*/watch_later'
instignore:
- '*/watch_later/*'
- '*/watch_later'
profiles:
p1:
dotfiles:
Expand Down Expand Up @@ -97,7 +97,7 @@ config:
dotpath: dotfiles
ignoreempty: true
impignore:
- '*/watch_later/*'
- '*/watch_later'
dotfiles:
profiles:
_EOF
Expand Down

0 comments on commit 55caaf6

Please sign in to comment.