mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-09 20:29:16 +00:00
First attempt at implementing negative ignore patterns
This commit is contained in:
@@ -203,9 +203,18 @@ def must_ignore(paths, ignores, debug=False):
|
|||||||
return False
|
return False
|
||||||
if debug:
|
if debug:
|
||||||
LOG.dbg('must ignore? \"{}\" against {}'.format(paths, ignores))
|
LOG.dbg('must ignore? \"{}\" against {}'.format(paths, ignores))
|
||||||
|
do_not_ignore = []
|
||||||
for p in paths:
|
for p in paths:
|
||||||
for i in ignores:
|
for i in ignores:
|
||||||
if fnmatch.fnmatch(p, i):
|
if i.startswith('!'):
|
||||||
|
i = i[1:]
|
||||||
|
if fnmatch.fnmatch(p, i):
|
||||||
|
if debug:
|
||||||
|
LOG.dbg('negative ignore \"{}\" match: {}'.format('!' + i, p))
|
||||||
|
do_not_ignore.append(p)
|
||||||
|
elif fnmatch.fnmatch(p, i):
|
||||||
|
if p in do_not_ignore:
|
||||||
|
continue
|
||||||
if debug:
|
if debug:
|
||||||
LOG.dbg('ignore \"{}\" match: {}'.format(i, p))
|
LOG.dbg('ignore \"{}\" match: {}'.format(i, p))
|
||||||
return True
|
return True
|
||||||
@@ -229,18 +238,31 @@ def patch_ignores(ignores, prefix, debug=False):
|
|||||||
if debug:
|
if debug:
|
||||||
LOG.dbg('ignores before patching: {}'.format(ignores))
|
LOG.dbg('ignores before patching: {}'.format(ignores))
|
||||||
for ignore in ignores:
|
for ignore in ignores:
|
||||||
|
negative = ignore.startswith('!')
|
||||||
|
if negative:
|
||||||
|
ignore = ignore[1:]
|
||||||
|
|
||||||
if os.path.isabs(ignore):
|
if os.path.isabs(ignore):
|
||||||
# is absolute
|
# is absolute
|
||||||
new.append(ignore)
|
if negative:
|
||||||
|
new.append('!' + ignore)
|
||||||
|
else:
|
||||||
|
new.append(ignore)
|
||||||
continue
|
continue
|
||||||
if STAR in ignore:
|
if STAR in ignore:
|
||||||
if ignore.startswith(STAR) or ignore.startswith(os.sep):
|
if ignore.startswith(STAR) or ignore.startswith(os.sep):
|
||||||
# is glob
|
# is glob
|
||||||
new.append(ignore)
|
if negative:
|
||||||
|
new.append('!' + ignore)
|
||||||
|
else:
|
||||||
|
new.append(ignore)
|
||||||
continue
|
continue
|
||||||
# patch ignore
|
# patch ignore
|
||||||
path = os.path.join(prefix, ignore)
|
path = os.path.join(prefix, ignore)
|
||||||
new.append(path)
|
if negative:
|
||||||
|
new.append('!' + path)
|
||||||
|
else:
|
||||||
|
new.append(path)
|
||||||
if debug:
|
if debug:
|
||||||
LOG.dbg('ignores after patching: {}'.format(new))
|
LOG.dbg('ignores after patching: {}'.format(new))
|
||||||
return new
|
return new
|
||||||
|
|||||||
Reference in New Issue
Block a user