1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-04 20:19:46 +00:00

fix relative cmpignore for #149

This commit is contained in:
deadc0de6
2019-06-09 13:44:18 +02:00
parent bbe6bc76fe
commit acc2c83e22
4 changed files with 64 additions and 7 deletions

View File

@@ -221,6 +221,8 @@ def cmd_compare(o, tmp):
tmpsrc = None
if dotfile.trans_r:
# apply transformation
if o.debug:
LOG.dbg('applying transformation before comparing')
tmpsrc = apply_trans(o.dotpath, dotfile, debug=o.debug)
if not tmpsrc:
# could not apply trans
@@ -245,7 +247,7 @@ def cmd_compare(o, tmp):
same = False
continue
ignores = list(set(o.compare_ignore + dotfile.cmpignore))
ignores = patch_ignores(ignores, dotfile.dst)
ignores = patch_ignores(ignores, dotfile.dst, debug=o.debug)
diff = comp.compare(insttmp, dotfile.dst, ignore=ignores)
if tmpsrc:
# clean tmp transformed dotfile if any
@@ -570,6 +572,9 @@ def main():
LOG.err('config file error: {}'.format(str(e)))
return False
if o.debug:
LOG.dbg('\n\n')
ret = True
try:

View File

@@ -78,7 +78,7 @@ class Updater:
ret = False
new_path = None
ignores = list(set(self.ignore + dotfile.upignore))
self.ignores = patch_ignores(ignores, dotfile.dst)
self.ignores = patch_ignores(ignores, dotfile.dst, debug=self.debug)
if self.debug:
self.log.dbg('ignore pattern(s): {}'.format(self.ignores))

View File

@@ -124,6 +124,8 @@ def must_ignore(paths, ignores, debug=False):
"""return true if any paths in list matches any ignore patterns"""
if not ignores:
return False
if debug:
LOG.dbg('must ignore? {} against {}'.format(paths, ignores))
for p in paths:
for i in ignores:
if fnmatch.fnmatch(p, i):
@@ -142,19 +144,24 @@ def uniq_list(a_list):
return new
def patch_ignores(ignores, prefix):
def patch_ignores(ignores, prefix, debug=False):
"""allow relative ignore pattern"""
new = []
if debug:
LOG.dbg('ignores before patching: {}'.format(ignores))
for ignore in ignores:
if STAR in ignore:
# is glob
new.append(ignore)
continue
if os.path.isabs(ignore):
# is absolute
new.append(ignore)
continue
if STAR in ignore:
if ignore.startswith(STAR) or ignore.startswith(os.sep):
# is glob
new.append(ignore)
continue
# patch upignore
path = os.path.join(prefix, ignore)
new.append(path)
if debug:
LOG.dbg('ignores after patching: {}'.format(new))
return new

View File

@@ -136,6 +136,51 @@ cd ${ddpath} | ${bin} compare -c ${cfg2} --verbose -C ${tmpd}/vscode
[ "$?" != "0" ] && exit 1
set -e
####################
# test for #149
####################
mkdir -p ${tmpd}/.zsh
touch ${tmpd}/.zsh/somefile
mkdir -p ${tmpd}/.zsh/plugins
touch ${tmpd}/.zsh/plugins/someplugin
echo "[+] import .zsh"
cd ${ddpath} | ${bin} import -c ${cfg} ${tmpd}/.zsh
# no diff expected
echo "[+] comparing .zsh"
cd ${ddpath} | ${bin} compare -c ${cfg} --verbose -C ${tmpd}/.zsh --ignore=${patt}
[ "$?" != "0" ] && exit 1
# add some files
touch ${tmpd}/.zsh/plugins/ignore-1.zsh
touch ${tmpd}/.zsh/plugins/ignore-2.zsh
# expects diff
echo "[+] comparing .zsh with new files"
set +e
cd ${ddpath} | ${bin} compare -c ${cfg} --verbose -C ${tmpd}/.zsh
ret="$?"
echo ${ret}
[ "${ret}" = "0" ] && exit 1
set -e
# expects no diff
patt="plugins/ignore-*.zsh"
echo "[+] comparing with ignore (pattern: ${patt}) - no diff expected"
set +e
cd ${ddpath} | ${bin} compare -c ${cfg} --verbose -C ${tmpd}/.zsh --ignore=${patt}
[ "$?" != "0" ] && exit 1
set -e
# expects no diff
echo "[+] comparing with ignore in dotfile - no diff expected"
sed '/d_zsh:/a \ \ \ \ cmpignore:\n\ \ \ \ - "plugins/ignore-*.zsh"' ${cfg} > ${cfg2}
set +e
cd ${ddpath} | ${bin} compare -c ${cfg2} --verbose -C ${tmpd}/.zsh
[ "$?" != "0" ] && exit 1
set -e
## CLEANING
rm -rf ${basedir} ${tmpd}