diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index ff91b31..98d442c 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -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: diff --git a/dotdrop/updater.py b/dotdrop/updater.py index 48df214..b19fa3f 100644 --- a/dotdrop/updater.py +++ b/dotdrop/updater.py @@ -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)) diff --git a/dotdrop/utils.py b/dotdrop/utils.py index ac36a74..9300d9b 100644 --- a/dotdrop/utils.py +++ b/dotdrop/utils.py @@ -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 diff --git a/tests-ng/compare-ignore-relative.sh b/tests-ng/compare-ignore-relative.sh index 46d6779..8d18c22 100755 --- a/tests-ng/compare-ignore-relative.sh +++ b/tests-ng/compare-ignore-relative.sh @@ -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}