]> arthur.barton.de Git - bup.git/blob - t/test-rm.sh
test-restore-map-owner: accommodate python 3 and test there
[bup.git] / t / test-rm.sh
1 #!/usr/bin/env bash
2 . ./wvtest-bup.sh || exit $?
3 . ./t/lib.sh || exit $?
4
5 top="$(WVPASS pwd)" || exit $?
6 tmpdir="$(WVPASS wvmktempdir)" || exit $?
7
8 export BUP_DIR="$tmpdir/bup"
9 export GIT_DIR="$tmpdir/bup"
10
11
12 bup() { "$top/bup" "$@"; }
13 compare-trees() { "$top/t/compare-trees" "$@"; }
14
15 wv_matches_rx()
16 {
17     local caller_file=${BASH_SOURCE[0]}
18     local caller_line=${BASH_LINENO[0]}
19     local src="$caller_file:$caller_line"
20     if test $# -ne 2; then
21         echo "! $src wv_matches_rx requires 2 arguments FAILED" 1>&2
22         return
23     fi
24     local str="$1"
25     local rx="$2"
26     echo "Matching:" 1>&2 || exit $?
27     echo "$str" | sed 's/^\(.*\)/  \1/' 1>&2 || exit $?
28     echo "Against:" 1>&2 || exit $?
29     echo "$rx" | sed 's/^\(.*\)/  \1/' 1>&2 || exit $?
30     if [[ "$str" =~ ^${rx}$ ]]; then
31         echo "! $src regex matches ok" 1>&2 || exit $?
32     else
33         echo "! $src regex doesn't match FAILED" 1>&2 || exit $?
34     fi
35 }
36
37
38 WVPASS bup init
39 WVPASS cd "$tmpdir"
40
41
42 WVSTART "rm /foo (lone branch)"
43 WVPASS mkdir src src/foo
44 WVPASS echo twisty-maze > src/1
45 WVPASS bup index src
46 WVPASS bup save -n src src
47 WVPASS "$top"/t/sync-tree bup/ bup-baseline/
48 # FIXME: test -n
49 WVPASS bup tick # Make sure we always get the timestamp changes below
50 WVPASS bup rm --unsafe /src
51 observed="$(compare-trees bup/ bup-baseline/ | LC_ALL=C sort)" || exit $?
52 wv_matches_rx "$observed" \
53 '\*deleting[ ]+logs/refs/heads/src
54 \*deleting[ ]+refs/heads/src(
55 \.d\.\.t\.\.\.[.]*[ ]+\./)?
56 \.d\.\.t\.\.\.[.]*[ ]+logs/refs/heads/
57 \.d\.\.t\.\.\.[.]*[ ]+refs/heads/(
58 >f\+\+\+\+\+\+\+\+\+[ ]+packed-refs)?'
59
60
61 WVSTART "rm /foo (one of many)"
62 WVPASS rm -rf bup
63 WVPASS mv bup-baseline bup
64 WVPASS echo twisty-maze > src/2
65 WVPASS bup index src
66 WVPASS bup save -n src-2 src
67 WVPASS echo twisty-maze > src/3
68 WVPASS bup index src
69 WVPASS bup save -n src-3 src
70 WVPASS "$top"/t/sync-tree bup/ bup-baseline/
71 WVPASS bup tick # Make sure we always get the timestamp changes below
72 WVPASS bup rm --unsafe /src
73 observed="$(compare-trees bup/ bup-baseline/ | LC_ALL=C sort)" || exit $?
74 wv_matches_rx "$observed" \
75 "\*deleting[ ]+logs/refs/heads/src
76 \*deleting[ ]+refs/heads/src(
77 \.d\.\.t\.\.\.[.]*[ ]+\./)?
78 \.d\.\.t\.\.\.[.]*[ ]+logs/refs/heads/
79 \.d\.\.t\.\.\.[.]*[ ]+refs/heads/(
80 >f\+\+\+\+\+\+\+\+\+[ ]+packed-refs)?"
81
82
83 WVSTART "rm /foo /bar (multiple of many)"
84 WVPASS rm -rf bup
85 WVPASS mv bup-baseline bup
86 WVPASS echo twisty-maze > src/4
87 WVPASS bup index src
88 WVPASS bup save -n src-4 src
89 WVPASS echo twisty-maze > src/5
90 WVPASS bup index src
91 WVPASS bup save -n src-5 src
92 WVPASS "$top"/t/sync-tree bup/ bup-baseline/
93 WVPASS bup tick # Make sure we always get the timestamp changes below
94 WVPASS bup rm --unsafe /src-2 /src-4
95 observed="$(compare-trees bup/ bup-baseline/ | LC_ALL=C sort)" || exit $?
96 wv_matches_rx "$observed" \
97 "\*deleting[ ]+logs/refs/heads/src-2
98 \*deleting[ ]+logs/refs/heads/src-4
99 \*deleting[ ]+refs/heads/src-2
100 \*deleting[ ]+refs/heads/src-4(
101 \.d\.\.t\.\.\.[.]*[ ]+\./)?
102 \.d\.\.t\.\.\.[.]*[ ]+logs/refs/heads/
103 \.d\.\.t\.\.\.[.]*[ ]+refs/heads/(
104 >f\+\+\+\+\+\+\+\+\+[ ]+packed-refs)?"
105
106
107 WVSTART "rm /foo /bar (all)"
108 WVPASS rm -rf bup
109 WVPASS mv bup-baseline bup
110 WVPASS "$top"/t/sync-tree bup/ bup-baseline/
111 WVPASS bup tick # Make sure we always get the timestamp changes below
112 WVPASS bup rm --unsafe /src /src-2 /src-3 /src-4 /src-5
113 observed="$(compare-trees bup/ bup-baseline/ | LC_ALL=C sort)" || exit $?
114 wv_matches_rx "$observed" \
115 "\*deleting[ ]+logs/refs/heads/src
116 \*deleting[ ]+logs/refs/heads/src-2
117 \*deleting[ ]+logs/refs/heads/src-3
118 \*deleting[ ]+logs/refs/heads/src-4
119 \*deleting[ ]+logs/refs/heads/src-5
120 \*deleting[ ]+refs/heads/src
121 \*deleting[ ]+refs/heads/src-2
122 \*deleting[ ]+refs/heads/src-3
123 \*deleting[ ]+refs/heads/src-4
124 \*deleting[ ]+refs/heads/src-5(
125 \.d\.\.t\.\.\.[.]*[ ]+\./)?
126 \.d\.\.t\.\.\.[.]*[ ]+logs/refs/heads/
127 \.d\.\.t\.\.\.[.]*[ ]+refs/heads/(
128 >f\+\+\+\+\+\+\+\+\+[ ]+packed-refs)?"
129
130
131 WVSTART "rm /foo/bar (lone save - equivalent to rm /foo)"
132 WVPASS rm -rf bup bup-baseline src
133 WVPASS bup init
134 WVPASS mkdir src
135 WVPASS echo twisty-maze > src/1
136 WVPASS bup index src
137 WVPASS bup save -n src src
138 WVPASS bup ls src > tmp-ls
139 save1="$(WVPASS head -n 1 tmp-ls)" || exit $?
140 WVPASS "$top"/t/sync-tree bup/ bup-baseline/
141 WVPASS bup tick # Make sure we always get the timestamp changes below
142 WVFAIL bup rm --unsafe /src/latest
143 WVPASS bup rm --unsafe /src/"$save1"
144 observed="$(compare-trees bup/ bup-baseline/ | LC_ALL=C sort)" || exit $?
145 wv_matches_rx "$observed" \
146 "\*deleting[ ]+logs/refs/heads/src
147 \*deleting[ ]+refs/heads/src(
148 \.d\.\.t\.\.\.[.]*[ ]+\./)?
149 \.d\.\.t\.\.\.[.]*[ ]+logs/refs/heads/
150 \.d\.\.t\.\.\.[.]*[ ]+refs/heads/(
151 >f\+\+\+\+\+\+\+\+\+[ ]+packed-refs)?"
152
153
154 verify-changes-caused-by-rewriting-save()
155 {
156     local before="$1" after="$2" tmpdir
157     tmpdir="$(WVPASS wvmktempdir)" || exit $?
158     (WVPASS cd "$before" && WVPASS find . | WVPASS sort) \
159         > "$tmpdir/before" || exit $?
160     (WVPASS cd "$after" && WVPASS find . | WVPASS sort) \
161         > "$tmpdir/after" || exit $?
162     local new_paths new_idx new_pack observed
163     new_paths="$(WVPASS comm -13 "$tmpdir/before" "$tmpdir/after")" || exit $?
164     new_idx="$(echo "$new_paths" | WVPASS grep -E '^\./objects/pack/pack-.*\.idx$' | cut -b 3-)" || exit $?
165     new_pack="$(echo "$new_paths" | WVPASS grep -E '^\./objects/pack/pack-.*\.pack$' | cut -b 3-)" || exit $?
166     wv_matches_rx "$(compare-trees "$after/" "$before/")" \
167 ">fcst\.\.\.[.]*[ ]+logs/refs/heads/src
168 \.d\.\.t\.\.\.[.]*[ ]+objects/
169 \.d\.\.t\.\.\.[.]*[ ]+objects/pack/
170 >fcst\.\.\.[.]*[ ]+objects/pack/bup\.bloom
171 >f\+\+\+\+\+\+\+[+]*[ ]+$new_idx
172 >f\+\+\+\+\+\+\+[+]*[ ]+$new_pack
173 \.d\.\.t\.\.\.[.]*[ ]+refs/heads/
174 >fc\.t\.\.\.[.]*[ ]+refs/heads/src"
175     WVPASS rm -rf "$tmpdir"
176 }
177
178 commit-hash-n()
179 {
180     local n="$1" repo="$2" branch="$3"
181     GIT_DIR="$repo" WVPASS git rev-list --reverse "$branch" \
182         | WVPASS awk "FNR == $n"
183 }
184
185 rm-safe-cinfo()
186 {
187     local n="$1" repo="$2" branch="$3" hash
188     hash="$(commit-hash-n "$n" "$repo" "$branch")" || exit $?
189     local fmt='Tree: %T%n'
190     fmt="${fmt}Author: %an <%ae> %ai%n"
191     fmt="${fmt}Committer: %cn <%ce> %ci%n"
192     fmt="${fmt}%n%s%n%b"
193     GIT_DIR="$repo" WVPASS git log -n1 --pretty=format:"$fmt" "$hash"
194 }
195
196
197 WVSTART 'rm /foo/BAR (setup)'
198 WVPASS rm -rf bup bup-baseline src
199 WVPASS bup init
200 WVPASS mkdir src
201 WVPASS echo twisty-maze > src/1
202 WVPASS bup index src
203 WVPASS bup save -n src src
204 WVPASS echo twisty-maze > src/2
205 WVPASS bup index src
206 WVPASS bup tick
207 WVPASS bup save -n src src
208 WVPASS echo twisty-maze > src/3
209 WVPASS bup index src
210 WVPASS bup tick
211 WVPASS bup save -n src src
212 WVPASS mv bup bup-baseline
213 WVPASS bup tick # Make sure we always get the timestamp changes below
214
215
216 WVSTART "rm /foo/BAR (first of many)"
217 WVPASS "$top"/t/sync-tree bup-baseline/ bup/
218 WVPASS bup ls src > tmp-ls
219 victim="$(WVPASS head -n 1 tmp-ls)" || exit $?
220 WVPASS bup rm --unsafe /src/"$victim"
221 verify-changes-caused-by-rewriting-save bup-baseline bup
222 observed=$(WVPASS git rev-list src | WVPASS wc -l) || exit $?
223 WVPASSEQ 2 $observed
224 WVPASSEQ "$(rm-safe-cinfo 1 bup src)" "$(rm-safe-cinfo 2 bup-baseline src)"
225 WVPASSEQ "$(rm-safe-cinfo 2 bup src)" "$(rm-safe-cinfo 3 bup-baseline src)"
226
227
228 WVSTART "rm /foo/BAR (one of many)"
229 WVPASS "$top"/t/sync-tree bup-baseline/ bup/
230 victim="$(WVPASS bup ls src | tail -n +2 | head -n 1)" || exit $?
231 WVPASS bup rm --unsafe /src/"$victim"
232 verify-changes-caused-by-rewriting-save bup-baseline bup
233 observed=$(git rev-list src | wc -l) || exit $?
234 WVPASSEQ 2 $observed
235 WVPASSEQ "$(commit-hash-n 1 bup src)" "$(commit-hash-n 1 bup-baseline src)"
236 WVPASSEQ "$(rm-safe-cinfo 2 bup src)" "$(rm-safe-cinfo 3 bup-baseline src)"
237
238
239 WVSTART "rm /foo/BAR (last of many)"
240 WVPASS "$top"/t/sync-tree bup-baseline/ bup/
241 victim="$(WVPASS bup ls src | tail -n 2 | head -n 1)" || exit $?
242 WVPASS bup rm --unsafe -vv /src/"$victim"
243 observed="$(compare-trees bup/ bup-baseline/ | LC_ALL=C sort)" || exit $?
244 wv_matches_rx "$observed" \
245 "\.d\.\.t\.\.\.[.]*[ ]+refs/heads/
246 >fc\.t\.\.\.[.]*[ ]+refs/heads/src
247 >fcst\.\.\.[.]*[ ]+logs/refs/heads/src"
248 observed=$(git rev-list src | wc -l) || exit $?
249 WVPASSEQ 2 $observed
250 WVPASSEQ "$(commit-hash-n 1 bup src)" "$(commit-hash-n 1 bup-baseline src)"
251 WVPASSEQ "$(commit-hash-n 2 bup src)" "$(commit-hash-n 2 bup-baseline src)"
252
253
254 # FIXME: test that committer changes when rewriting, when appropriate
255
256 WVPASS rm -rf "$tmpdir"