mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-09 23:59:16 +00:00
handle reimport of file within imported directory
This commit is contained in:
@@ -353,7 +353,21 @@ def cmd_importer(o):
|
|||||||
|
|
||||||
# prepare hierarchy for dotfile
|
# prepare hierarchy for dotfile
|
||||||
srcf = os.path.join(o.dotpath, src)
|
srcf = os.path.join(o.dotpath, src)
|
||||||
if not os.path.exists(srcf):
|
overwrite = not os.path.exists(srcf)
|
||||||
|
if o.safe and os.path.exists(srcf):
|
||||||
|
c = Comparator(debug=o.debug)
|
||||||
|
diff = c.compare(srcf, dst)
|
||||||
|
if diff != '':
|
||||||
|
# files are different, dunno what to do
|
||||||
|
LOG.log('diff \"{}\" VS \"{}\"'.format(dst, srcf))
|
||||||
|
LOG.emph(diff)
|
||||||
|
# ask user
|
||||||
|
msg = 'Dotfile \"{}\" already exists, overwrite?'.format(srcf)
|
||||||
|
overwrite = LOG.ask(msg)
|
||||||
|
|
||||||
|
if o.debug:
|
||||||
|
LOG.dbg('will overwrite: {}'.format(overwrite))
|
||||||
|
if overwrite:
|
||||||
cmd = ['mkdir', '-p', '{}'.format(os.path.dirname(srcf))]
|
cmd = ['mkdir', '-p', '{}'.format(os.path.dirname(srcf))]
|
||||||
if o.dry:
|
if o.dry:
|
||||||
LOG.dry('would run: {}'.format(' '.join(cmd)))
|
LOG.dry('would run: {}'.format(' '.join(cmd)))
|
||||||
|
|||||||
89
tests-ng/import-subfile.sh
Executable file
89
tests-ng/import-subfile.sh
Executable file
@@ -0,0 +1,89 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# author: deadc0de6 (https://github.com/deadc0de6)
|
||||||
|
# Copyright (c) 2019, deadc0de6
|
||||||
|
#
|
||||||
|
# test import file in directory
|
||||||
|
# after having imported directory
|
||||||
|
#
|
||||||
|
|
||||||
|
# exit on first error
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# all this crap to get current path
|
||||||
|
rl="readlink -f"
|
||||||
|
if ! ${rl} "${0}" >/dev/null 2>&1; then
|
||||||
|
rl="realpath"
|
||||||
|
|
||||||
|
if ! hash ${rl}; then
|
||||||
|
echo "\"${rl}\" not found !" && exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
cur=$(dirname "$(${rl} "${0}")")
|
||||||
|
|
||||||
|
#hash dotdrop >/dev/null 2>&1
|
||||||
|
#[ "$?" != "0" ] && echo "install dotdrop to run tests" && exit 1
|
||||||
|
|
||||||
|
#echo "called with ${1}"
|
||||||
|
|
||||||
|
# dotdrop path can be pass as argument
|
||||||
|
ddpath="${cur}/../"
|
||||||
|
[ "${1}" != "" ] && ddpath="${1}"
|
||||||
|
[ ! -d ${ddpath} ] && echo "ddpath \"${ddpath}\" is not a directory" && exit 1
|
||||||
|
|
||||||
|
export PYTHONPATH="${ddpath}:${PYTHONPATH}"
|
||||||
|
bin="python3 -m dotdrop.dotdrop"
|
||||||
|
|
||||||
|
echo "dotdrop path: ${ddpath}"
|
||||||
|
echo "pythonpath: ${PYTHONPATH}"
|
||||||
|
|
||||||
|
# get the helpers
|
||||||
|
source ${cur}/helpers
|
||||||
|
|
||||||
|
echo -e "\e[96m\e[1m==> RUNNING $(basename $BASH_SOURCE) <==\e[0m"
|
||||||
|
|
||||||
|
################################################################
|
||||||
|
# this is the test
|
||||||
|
################################################################
|
||||||
|
|
||||||
|
# the dotfile source
|
||||||
|
tmps=`mktemp -d --suffix='-dotdrop-tests'`
|
||||||
|
mkdir -p ${tmps}/dotfiles
|
||||||
|
# the dotfile destination
|
||||||
|
tmpd=`mktemp -d --suffix='-dotdrop-tests'`
|
||||||
|
#echo "dotfile destination: ${tmpd}"
|
||||||
|
|
||||||
|
# create the dotfile
|
||||||
|
mkdir -p ${tmpd}/adir
|
||||||
|
echo "first" > ${tmpd}/adir/file1
|
||||||
|
|
||||||
|
# create the config file
|
||||||
|
cfg="${tmps}/config.yaml"
|
||||||
|
|
||||||
|
cat > ${cfg} << _EOF
|
||||||
|
config:
|
||||||
|
backup: true
|
||||||
|
create: true
|
||||||
|
dotpath: dotfiles
|
||||||
|
dotfiles:
|
||||||
|
profiles:
|
||||||
|
_EOF
|
||||||
|
#cat ${cfg}
|
||||||
|
|
||||||
|
# import dir
|
||||||
|
cd ${ddpath} | ${bin} import -c ${cfg} -p p1 -V ${tmpd}/adir
|
||||||
|
|
||||||
|
# change the file
|
||||||
|
echo "second" > ${tmpd}/adir/file1
|
||||||
|
|
||||||
|
# import file
|
||||||
|
cd ${ddpath} | ${bin} import -c ${cfg} -p p1 -V ${tmpd}/adir/file1
|
||||||
|
|
||||||
|
# test
|
||||||
|
[ ! -e ${tmps}/dotfiles/${tmpd}/adir/file1 ] && echo "not exist" && exit 1
|
||||||
|
grep 'second' ${tmps}/dotfiles/${tmpd}/adir/file1
|
||||||
|
|
||||||
|
## CLEANING
|
||||||
|
rm -rf ${tmps} ${tmpd}
|
||||||
|
|
||||||
|
echo "OK"
|
||||||
|
exit 0
|
||||||
Reference in New Issue
Block a user