mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-08 23:04:15 +00:00
fix relative cmpignore for #149
This commit is contained in:
@@ -221,6 +221,8 @@ def cmd_compare(o, tmp):
|
|||||||
tmpsrc = None
|
tmpsrc = None
|
||||||
if dotfile.trans_r:
|
if dotfile.trans_r:
|
||||||
# apply transformation
|
# apply transformation
|
||||||
|
if o.debug:
|
||||||
|
LOG.dbg('applying transformation before comparing')
|
||||||
tmpsrc = apply_trans(o.dotpath, dotfile, debug=o.debug)
|
tmpsrc = apply_trans(o.dotpath, dotfile, debug=o.debug)
|
||||||
if not tmpsrc:
|
if not tmpsrc:
|
||||||
# could not apply trans
|
# could not apply trans
|
||||||
@@ -245,7 +247,7 @@ def cmd_compare(o, tmp):
|
|||||||
same = False
|
same = False
|
||||||
continue
|
continue
|
||||||
ignores = list(set(o.compare_ignore + dotfile.cmpignore))
|
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)
|
diff = comp.compare(insttmp, dotfile.dst, ignore=ignores)
|
||||||
if tmpsrc:
|
if tmpsrc:
|
||||||
# clean tmp transformed dotfile if any
|
# clean tmp transformed dotfile if any
|
||||||
@@ -570,6 +572,9 @@ def main():
|
|||||||
LOG.err('config file error: {}'.format(str(e)))
|
LOG.err('config file error: {}'.format(str(e)))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if o.debug:
|
||||||
|
LOG.dbg('\n\n')
|
||||||
|
|
||||||
ret = True
|
ret = True
|
||||||
try:
|
try:
|
||||||
|
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ class Updater:
|
|||||||
ret = False
|
ret = False
|
||||||
new_path = None
|
new_path = None
|
||||||
ignores = list(set(self.ignore + dotfile.upignore))
|
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:
|
if self.debug:
|
||||||
self.log.dbg('ignore pattern(s): {}'.format(self.ignores))
|
self.log.dbg('ignore pattern(s): {}'.format(self.ignores))
|
||||||
|
|
||||||
|
|||||||
@@ -124,6 +124,8 @@ def must_ignore(paths, ignores, debug=False):
|
|||||||
"""return true if any paths in list matches any ignore patterns"""
|
"""return true if any paths in list matches any ignore patterns"""
|
||||||
if not ignores:
|
if not ignores:
|
||||||
return False
|
return False
|
||||||
|
if debug:
|
||||||
|
LOG.dbg('must ignore? {} against {}'.format(paths, ignores))
|
||||||
for p in paths:
|
for p in paths:
|
||||||
for i in ignores:
|
for i in ignores:
|
||||||
if fnmatch.fnmatch(p, i):
|
if fnmatch.fnmatch(p, i):
|
||||||
@@ -142,19 +144,24 @@ def uniq_list(a_list):
|
|||||||
return new
|
return new
|
||||||
|
|
||||||
|
|
||||||
def patch_ignores(ignores, prefix):
|
def patch_ignores(ignores, prefix, debug=False):
|
||||||
"""allow relative ignore pattern"""
|
"""allow relative ignore pattern"""
|
||||||
new = []
|
new = []
|
||||||
|
if debug:
|
||||||
|
LOG.dbg('ignores before patching: {}'.format(ignores))
|
||||||
for ignore in ignores:
|
for ignore in ignores:
|
||||||
if STAR in ignore:
|
|
||||||
# is glob
|
|
||||||
new.append(ignore)
|
|
||||||
continue
|
|
||||||
if os.path.isabs(ignore):
|
if os.path.isabs(ignore):
|
||||||
# is absolute
|
# is absolute
|
||||||
new.append(ignore)
|
new.append(ignore)
|
||||||
continue
|
continue
|
||||||
|
if STAR in ignore:
|
||||||
|
if ignore.startswith(STAR) or ignore.startswith(os.sep):
|
||||||
|
# is glob
|
||||||
|
new.append(ignore)
|
||||||
|
continue
|
||||||
# patch upignore
|
# patch upignore
|
||||||
path = os.path.join(prefix, ignore)
|
path = os.path.join(prefix, ignore)
|
||||||
new.append(path)
|
new.append(path)
|
||||||
|
if debug:
|
||||||
|
LOG.dbg('ignores after patching: {}'.format(new))
|
||||||
return new
|
return new
|
||||||
|
|||||||
@@ -136,6 +136,51 @@ cd ${ddpath} | ${bin} compare -c ${cfg2} --verbose -C ${tmpd}/vscode
|
|||||||
[ "$?" != "0" ] && exit 1
|
[ "$?" != "0" ] && exit 1
|
||||||
set -e
|
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
|
## CLEANING
|
||||||
rm -rf ${basedir} ${tmpd}
|
rm -rf ${basedir} ${tmpd}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user