mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-12 01:18:59 +00:00
fix relative cmpignore for #149
This commit is contained in:
@@ -115,9 +115,9 @@ class Comparator:
|
|||||||
|
|
||||||
def _diff(self, left, right, header=False):
|
def _diff(self, left, right, header=False):
|
||||||
"""diff using the unix tool diff"""
|
"""diff using the unix tool diff"""
|
||||||
d = diff(left, right, raw=False,
|
out = diff(left, right, raw=False,
|
||||||
opts=self.diffopts, debug=self.debug)
|
opts=self.diffopts, debug=self.debug)
|
||||||
if header:
|
if header:
|
||||||
lshort = os.path.basename(left)
|
lshort = os.path.basename(left)
|
||||||
d = '=> diff \"{}\":\n{}'.format(lshort, diff)
|
out = '=> diff \"{}\":\n{}'.format(lshort, out)
|
||||||
return d
|
return out
|
||||||
|
|||||||
@@ -245,7 +245,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.src)
|
ignores = patch_ignores(ignores, dotfile.dst)
|
||||||
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
|
||||||
|
|||||||
@@ -54,10 +54,9 @@ echo "[+] dotpath dir: ${basedir}/dotfiles"
|
|||||||
tmpd=`mktemp -d --suffix='-dotdrop-tests'`
|
tmpd=`mktemp -d --suffix='-dotdrop-tests'`
|
||||||
|
|
||||||
# some files
|
# some files
|
||||||
mkdir -p ${tmpd}/{program,config}
|
mkdir -p ${tmpd}/{program,config,vscode}
|
||||||
touch ${tmpd}/program/a
|
touch ${tmpd}/program/a
|
||||||
touch ${tmpd}/config/a
|
touch ${tmpd}/config/a
|
||||||
mkdir ${tmpd}/vscode
|
|
||||||
touch ${tmpd}/vscode/extensions.txt
|
touch ${tmpd}/vscode/extensions.txt
|
||||||
touch ${tmpd}/vscode/keybindings.json
|
touch ${tmpd}/vscode/keybindings.json
|
||||||
|
|
||||||
@@ -71,51 +70,35 @@ cd ${ddpath} | ${bin} import -c ${cfg} ${tmpd}/program
|
|||||||
cd ${ddpath} | ${bin} import -c ${cfg} ${tmpd}/config
|
cd ${ddpath} | ${bin} import -c ${cfg} ${tmpd}/config
|
||||||
cd ${ddpath} | ${bin} import -c ${cfg} ${tmpd}/vscode
|
cd ${ddpath} | ${bin} import -c ${cfg} ${tmpd}/vscode
|
||||||
|
|
||||||
# add files
|
# add files on filesystem
|
||||||
echo "[+] add files"
|
echo "[+] add files"
|
||||||
touch ${tmpd}/program/b
|
touch ${tmpd}/program/b
|
||||||
touch ${tmpd}/config/b
|
touch ${tmpd}/config/b
|
||||||
|
|
||||||
# expects diff
|
# expects diff
|
||||||
echo "[+] comparing normal - 2 diffs"
|
echo "[+] comparing normal - diffs expected"
|
||||||
set +e
|
set +e
|
||||||
cd ${ddpath} | ${bin} compare -c ${cfg} --verbose
|
cd ${ddpath} | ${bin} compare -c ${cfg} --verbose
|
||||||
[ "$?" = "0" ] && exit 1
|
ret="$?"
|
||||||
|
echo ${ret}
|
||||||
|
[ "${ret}" = "0" ] && exit 1
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# expects one diff
|
# expects one diff
|
||||||
patt="${tmpd}/config/b"
|
patt="b"
|
||||||
echo "[+] comparing with ignore (pattern: ${patt}) - 1 diff"
|
echo "[+] comparing with ignore (pattern: ${patt}) - no diff expected"
|
||||||
set +e
|
|
||||||
cd ${ddpath} | ${bin} compare -c ${cfg} --verbose --ignore=${patt}
|
|
||||||
[ "$?" = "0" ] && exit 1
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# expects no diff
|
|
||||||
patt="*b"
|
|
||||||
echo "[+] comparing with ignore (pattern: ${patt}) - 0 diff"
|
|
||||||
set +e
|
set +e
|
||||||
cd ${ddpath} | ${bin} compare -c ${cfg} --verbose --ignore=${patt}
|
cd ${ddpath} | ${bin} compare -c ${cfg} --verbose --ignore=${patt}
|
||||||
[ "$?" != "0" ] && exit 1
|
[ "$?" != "0" ] && exit 1
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# expects one diff
|
|
||||||
patt="*/config/*b"
|
|
||||||
echo "[+] comparing with ignore (pattern: ${patt}) - 1 diff"
|
|
||||||
set +e
|
|
||||||
cd ${ddpath} | ${bin} compare -c ${cfg} --verbose --ignore=${patt}
|
|
||||||
[ "$?" = "0" ] && exit 1
|
|
||||||
set -e
|
|
||||||
|
|
||||||
#cat ${cfg}
|
|
||||||
|
|
||||||
# adding ignore in dotfile
|
# adding ignore in dotfile
|
||||||
cfg2="${basedir}/config2.yaml"
|
cfg2="${basedir}/config2.yaml"
|
||||||
sed '/d_config:/a \ \ \ \ cmpignore:\n\ \ \ \ - "config/b"' ${cfg} > ${cfg2}
|
sed '/d_config:/a \ \ \ \ cmpignore:\n\ \ \ \ - "b"' ${cfg} > ${cfg2}
|
||||||
#cat ${cfg2}
|
#cat ${cfg2}
|
||||||
|
|
||||||
# expects one diff
|
# expects one diff
|
||||||
echo "[+] comparing with ignore in dotfile - 1 diff"
|
echo "[+] comparing with ignore in dotfile - diff expected"
|
||||||
set +e
|
set +e
|
||||||
cd ${ddpath} | ${bin} compare -c ${cfg2} --verbose
|
cd ${ddpath} | ${bin} compare -c ${cfg2} --verbose
|
||||||
[ "$?" = "0" ] && exit 1
|
[ "$?" = "0" ] && exit 1
|
||||||
@@ -128,8 +111,7 @@ sed -i '/d_program:/a \ \ \ \ cmpignore:\n\ \ \ \ - "b"' ${cfg2}
|
|||||||
#cat ${cfg2}
|
#cat ${cfg2}
|
||||||
|
|
||||||
# expects no diff
|
# expects no diff
|
||||||
patt="*b"
|
echo "[+] comparing with ignore in dotfile - no diff expected"
|
||||||
echo "[+] comparing with ignore in dotfile - 0 diff"
|
|
||||||
set +e
|
set +e
|
||||||
cd ${ddpath} | ${bin} compare -c ${cfg2} --verbose
|
cd ${ddpath} | ${bin} compare -c ${cfg2} --verbose
|
||||||
[ "$?" != "0" ] && exit 1
|
[ "$?" != "0" ] && exit 1
|
||||||
@@ -140,12 +122,14 @@ echo touched > ${tmpd}/vscode/extensions.txt
|
|||||||
echo touched > ${tmpd}/vscode/keybindings.json
|
echo touched > ${tmpd}/vscode/keybindings.json
|
||||||
|
|
||||||
# expect two diffs
|
# expect two diffs
|
||||||
|
echo "[+] comparing - diff expected"
|
||||||
set +e
|
set +e
|
||||||
cd ${ddpath} | ${bin} compare -c ${cfg} --verbose -C ${tmpd}/vscode
|
cd ${ddpath} | ${bin} compare -c ${cfg} --verbose -C ${tmpd}/vscode
|
||||||
[ "$?" = "0" ] && exit 1
|
[ "$?" = "0" ] && exit 1
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# expects no diff
|
# expects no diff
|
||||||
|
echo "[+] comparing with ignore in dotfile - no diff expected"
|
||||||
sed '/d_vscode:/a \ \ \ \ cmpignore:\n\ \ \ \ - "extensions.txt"\n\ \ \ \ - "keybindings.json"' ${cfg} > ${cfg2}
|
sed '/d_vscode:/a \ \ \ \ cmpignore:\n\ \ \ \ - "extensions.txt"\n\ \ \ \ - "keybindings.json"' ${cfg} > ${cfg2}
|
||||||
set +e
|
set +e
|
||||||
cd ${ddpath} | ${bin} compare -c ${cfg2} --verbose -C ${tmpd}/vscode
|
cd ${ddpath} | ${bin} compare -c ${cfg2} --verbose -C ${tmpd}/vscode
|
||||||
|
|||||||
Reference in New Issue
Block a user