diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index 625a109..5939385 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -345,11 +345,12 @@ def cmd_importer(o): src = strip_home(dst) if o.import_as: # handle import as - src = o.import_as.rstrip(os.sep) + src = os.path.expanduser(o.import_as) + src = src.rstrip(os.sep) src = os.path.abspath(src) src = strip_home(src) if o.debug: - LOG.dbg('import src for {}: {}'.format(dst, src)) + LOG.dbg('import src for {} as {}'.format(dst, src)) strip = '.' + os.sep if o.keepdot: diff --git a/tests-ng/import-as.sh b/tests-ng/import-as.sh index 065873d..34d7f98 100755 --- a/tests-ng/import-as.sh +++ b/tests-ng/import-as.sh @@ -44,6 +44,11 @@ echo -e "$(tput setaf 6)==> RUNNING $(basename $BASH_SOURCE) <==$(tput sgr0)" # this is the test ################################################################ +clean() +{ + rm -rf ${tmps} ${tmpd} ~/.dotdrop.test ~/.dotdrop-dotfiles-test +} + # the dotfile source tmps=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` mkdir -p ${tmps}/dotfiles @@ -113,10 +118,32 @@ nb=`cat ${cfg} | grep f_file3 | wc -l` cat ${cfg} | grep "src: config/adir" || exit 1 cat ${cfg} | grep "src: config2/file3" || exit 1 -cat ${cfg} +# test import from sub in home +mkdir -p ~/.dotdrop-dotfiles-test/{dotfiles,config} +cfg=~/.dotdrop-dotfiles-test/config/config.yaml +echo 'remove-me' > ~/.dotdrop.test +cat > ${cfg} << _EOF +config: + backup: true + banner: true + create: true + dotpath: ~/.dotdrop-dotfiles-test/dotfiles + keepdot: false + link_dotfile_default: nolink + link_on_import: nolink + longkey: true +dotfiles: +profiles: +_EOF + +cd ${ddpath} | ${bin} import -b -c ${cfg} -p test -V ~/.dotdrop.test --as=~/.whatever +#cat ${cfg} + +[ ! -e ~/.dotdrop-dotfiles-test/dotfiles/whatever ] && clean && echo 'tild imported' && exit 1 +cat ${cfg} | grep '~/.whatever' && clean && echo 'import with tild failed' && exit 1 ## CLEANING -rm -rf ${tmps} ${tmpd} +clean echo "OK" exit 0 diff --git a/tests-ng/re-import.sh b/tests-ng/re-import.sh index 5a95fa7..5974c31 100755 --- a/tests-ng/re-import.sh +++ b/tests-ng/re-import.sh @@ -44,6 +44,11 @@ echo -e "$(tput setaf 6)==> RUNNING $(basename $BASH_SOURCE) <==$(tput sgr0)" # this is the test ################################################################ +clean() +{ + rm -rf ${tmps} ${tmpd} ~/.dotdrop-test +} + # the dotfile source tmps=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` mkdir -p ${tmps}/dotfiles @@ -73,11 +78,11 @@ cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ${tmpd}/testfile cat ${cfg} # ensure exists and is not link -[ ! -e ${tmps}/dotfiles/${tmpd}/testfile ] && echo "does not exist" && exit 1 +[ ! -e ${tmps}/dotfiles/${tmpd}/testfile ] && echo "does not exist" && clean && exit 1 cat ${cfg} | grep ${tmpd}/testfile >/dev/null 2>&1 grep 'original' ${tmps}/dotfiles/${tmpd}/testfile nb=`cat ${cfg} | grep ${tmpd}/testfile | wc -l` -[ "${nb}" != "1" ] && echo 'not 1 entry' && exit 1 +[ "${nb}" != "1" ] && echo 'not 1 entry' && clean && exit 1 # re-import without changing echo "[+] re-import without changes" @@ -85,11 +90,11 @@ cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ${tmpd}/testfile cat ${cfg} # test is only once -[ ! -e ${tmps}/dotfiles/${tmpd}/testfile ] && echo "does not exist" && exit 1 +[ ! -e ${tmps}/dotfiles/${tmpd}/testfile ] && echo "does not exist" && clean && exit 1 cat ${cfg} | grep ${tmpd}/testfile >/dev/null 2>&1 grep 'original' ${tmps}/dotfiles/${tmpd}/testfile nb=`cat ${cfg} | grep ${tmpd}/testfile | wc -l` -[ "${nb}" != "1" ] && echo 'two entries!' && exit 1 +[ "${nb}" != "1" ] && echo 'two entries!' && clean && exit 1 # re-import with changes echo "[+] re-import with changes" @@ -98,11 +103,11 @@ cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ${tmpd}/testfile cat ${cfg} # test is only once -[ ! -e ${tmps}/dotfiles/${tmpd}/testfile ] && echo "does not exist" && exit 1 +[ ! -e ${tmps}/dotfiles/${tmpd}/testfile ] && echo "does not exist" && clean && exit 1 cat ${cfg} | grep ${tmpd}/testfile >/dev/null 2>&1 grep 'modified' ${tmps}/dotfiles/${tmpd}/testfile nb=`cat ${cfg} | grep ${tmpd}/testfile | wc -l` -[ "${nb}" != "1" ] && echo 'two entries!' && exit 1 +[ "${nb}" != "1" ] && echo 'two entries!' && clean && exit 1 # ################################################### @@ -113,11 +118,11 @@ cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ~/.dotdrop.test cat ${cfg} # ensure exists and is not link -[ ! -e "${tmps}/dotfiles/dotdrop.test" ] && echo "does not exist" && exit 1 +[ ! -e "${tmps}/dotfiles/dotdrop.test" ] && echo "does not exist" && clean && exit 1 cat ${cfg} | grep "~/.dotdrop.test" >/dev/null 2>&1 grep 'original' ${tmps}/dotfiles/dotdrop.test nb=`cat ${cfg} | grep "~/.dotdrop.test" | wc -l` -[ "${nb}" != "1" ] && echo 'not 1 entry' && exit 1 +[ "${nb}" != "1" ] && echo 'not 1 entry' && clean && exit 1 # re-import without changing echo "[+] re-import without changes in home" @@ -125,11 +130,11 @@ cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ~/.dotdrop.test cat ${cfg} # test is only once -[ ! -e "${tmps}/dotfiles/dotdrop.test" ] && echo "does not exist" && exit 1 +[ ! -e "${tmps}/dotfiles/dotdrop.test" ] && echo "does not exist" && clean && exit 1 cat ${cfg} | grep "~/.dotdrop.test" >/dev/null 2>&1 grep 'original' ${tmps}/dotfiles/dotdrop.test nb=`cat ${cfg} | grep "~/.dotdrop.test" | wc -l` -[ "${nb}" != "1" ] && echo 'two entries!' && exit 1 +[ "${nb}" != "1" ] && echo 'two entries!' && clean && exit 1 # re-import with changes echo "[+] re-import with changes in home" @@ -138,14 +143,14 @@ cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ~/.dotdrop.test cat ${cfg} # test is only once -[ ! -e "${tmps}/dotfiles/dotdrop.test" ] && echo "does not exist" && exit 1 +[ ! -e "${tmps}/dotfiles/dotdrop.test" ] && echo "does not exist" && clean && exit 1 cat ${cfg} | grep "~/.dotdrop.test" >/dev/null 2>&1 grep 'modified' ${tmps}/dotfiles/dotdrop.test nb=`cat ${cfg} | grep "~/.dotdrop.test" | wc -l` -[ "${nb}" != "1" ] && echo 'two entries!' && exit 1 +[ "${nb}" != "1" ] && echo 'two entries!' && clean && exit 1 ## CLEANING -rm -rf ${tmps} ${tmpd} ~/.dotdrop-test +clean echo "OK" exit 0