File: update.sh

package info (click to toggle)
dotdrop 1.15.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,812 kB
  • sloc: sh: 13,401; python: 8,186; makefile: 3
file content (123 lines) | stat: -rwxr-xr-x 3,808 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env bash
# author: deadc0de6 (https://github.com/deadc0de6)
# Copyright (c) 2017, deadc0de6
#
# test updates
# returns 1 in case of error
#

## start-cookie
set -eu -o errtrace -o pipefail
cur=$(cd "$(dirname "${0}")" && pwd)
ddpath="${cur}/../"
PPATH="{PYTHONPATH:-}"
export PYTHONPATH="${ddpath}:${PPATH}"
altbin="python3 -m dotdrop.dotdrop"
if hash coverage 2>/dev/null; then
  mkdir -p coverages/
  altbin="coverage run -p --data-file coverages/coverage --source=dotdrop -m dotdrop.dotdrop"
fi
bin="${DT_BIN:-${altbin}}"
# shellcheck source=tests-ng/helpers
source "${cur}"/helpers
echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)"
## end-cookie

################################################################
# this is the test
################################################################

# dotdrop directory
basedir=$(mktemp -d --suffix='-dotdrop-dotpath' || mktemp -d)
dotpath="${basedir}/dotfiles"
echo "[+] dotdrop dir: ${basedir}"
echo "[+] dotpath dir: ${dotpath}"

# the dotfile to be imported
tmpd=$(mktemp -d --suffix='-dotdrop-fs' || mktemp -d)

clear_on_exit "${basedir}"
clear_on_exit "${tmpd}"

# single file
echo 'unique' > "${tmpd}"/uniquefile

# hierarchy from https://pymotw.com/2/filecmp/
# create the hierarchy
# for dir1 (originally imported directory))))
mkdir "${tmpd}"/dir1
touch "${tmpd}"/dir1/file_only_in_dir1
mkdir -p "${tmpd}"/dir1/dir_only_in_dir1
touch "${tmpd}/dir1/dir_only_in_dir1/x"
mkdir -p "${tmpd}"/dir1/common_dir
touch "${tmpd}/dir1/common_dir/y"
echo 'this file is the same' > "${tmpd}"/dir1/common_file
echo 'in dir1' > "${tmpd}"/dir1/not_the_same
echo 'This is a file in dir1' > "${tmpd}"/dir1/file_in_dir1
mkdir -p "${tmpd}"/dir1/sub/sub2
mkdir -p "${tmpd}"/dir1/notindir2/notindir2
echo 'first' > "${tmpd}"/dir1/sub/sub2/different
#tree ${tmpd}/dir1

# create the hierarchy
# for dir2 (modified original for update)
mkdir "${tmpd}"/dir2
touch "${tmpd}"/dir2/file_only_in_dir2
mkdir -p "${tmpd}"/dir2/common_dir
touch "${tmpd}/dir2/common_dir/z"
echo 'this file is the same' > "${tmpd}"/dir2/common_file
echo 'in dir2' > "${tmpd}"/dir2/not_the_same
mkdir -p "${tmpd}"/dir2/file_in_dir1
mkdir -p "${tmpd}"/dir2/sub/sub2
echo 'modified' > "${tmpd}"/dir2/sub/sub2/different
mkdir -p "${tmpd}"/dir2/new/new2
touch "${tmpd}/dir2/new/new2/new"
mkdir -p "${tmpd}"/dir2/sub1/sub2/sub3/
touch "${tmpd}"/dir2/sub1/sub2/sub3/file
#tree ${tmpd}/dir2

# create the config file
cfg="${basedir}/config.yaml"
create_conf "${cfg}" # sets token

# import dir1
echo "[+] import"
cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/dir1
cd "${ddpath}" | ${bin} import -f -c "${cfg}" "${tmpd}"/uniquefile

# let's see the dotpath
#tree ${basedir}/dotfiles

# change dir1 to dir2 in deployed
echo "[+] change dir"
rm -rf "${tmpd}"/dir1
mv "${tmpd}"/dir2 "${tmpd}"/dir1
#tree ${tmpd}/dir1

# change unique file
echo 'changed' > "${tmpd}"/uniquefile

# compare
#echo "[+] comparing"
#cd ${ddpath} | ${bin} compare -c ${cfg}

# update
echo "[+] updating"
cd "${ddpath}" | ${bin} update -c "${cfg}" -f --verbose "${tmpd}"/uniquefile "${tmpd}"/dir1
grep 'changed' "${dotpath}/${tmpd}/uniquefile"
[ ! -e "${dotpath}/${tmpd}/dir1/file_only_in_dir2" ] && echo "file_only_in_dir2 not found" && exit 1
[ -f "${dotpath}/${tmpd}/dir1/file_in_dir1" ] && echo "directory \"file_in_dir1\" not removed" && exit 1

# manually update
mkdir -p "${dotpath}/${tmpd}/dir1/file_in_dir1"

# ensure changes applied correctly
echo "diff dir1"
tree "${tmpd}"/dir1
diff -r --suppress-common-lines "${tmpd}"/dir1 "${dotpath}/${tmpd}/dir1"
echo "diff uniquefile"
diff "${tmpd}"/uniquefile "${basedir}"/dotfiles/"${tmpd}"/uniquefile
[ ! -e "${basedir}"/dotfiles/"${tmpd}"/dir1/sub1/sub2/sub3/file ] && echo "sub does not exist" && exit 1

echo "OK"
exit 0