2 . ./wvtest-bup.sh || exit $?
3 . ./dev/lib.sh || exit $?
5 top="$(WVPASS pwd)" || exit $?
6 tmpdir="$(WVPASS wvmktempdir)" || exit $?
8 export BUP_DIR="$tmpdir/bup"
9 export GIT_DIR="$tmpdir/bup"
12 bup() { "$top/bup" "$@"; }
13 compare-trees() { "$top/dev/compare-trees" "$@"; }
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
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 $?
33 echo "! $src regex doesn't match FAILED" 1>&2 || exit $?
42 WVSTART "rm /foo (lone branch)"
43 WVPASS mkdir src src/foo
44 WVPASS echo twisty-maze > src/1
46 WVPASS bup save -n src src
47 WVPASS "$top"/dev/sync-tree bup/ bup-baseline/
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)?'
61 WVSTART "rm /foo (one of many)"
63 WVPASS mv bup-baseline bup
64 WVPASS echo twisty-maze > src/2
66 WVPASS bup save -n src-2 src
67 WVPASS echo twisty-maze > src/3
69 WVPASS bup save -n src-3 src
70 WVPASS "$top"/dev/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)?"
83 WVSTART "rm /foo /bar (multiple of many)"
85 WVPASS mv bup-baseline bup
86 WVPASS echo twisty-maze > src/4
88 WVPASS bup save -n src-4 src
89 WVPASS echo twisty-maze > src/5
91 WVPASS bup save -n src-5 src
92 WVPASS "$top"/dev/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)?"
107 WVSTART "rm /foo /bar (all)"
109 WVPASS mv bup-baseline bup
110 WVPASS "$top"/dev/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)?"
131 WVSTART "rm /foo/bar (lone save - equivalent to rm /foo)"
132 WVPASS rm -rf bup bup-baseline src
135 WVPASS echo twisty-maze > src/1
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"/dev/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)?"
154 verify-changes-caused-by-rewriting-save()
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"
180 local n="$1" repo="$2" branch="$3"
181 GIT_DIR="$repo" WVPASS git rev-list --reverse "$branch" \
182 | WVPASS awk "FNR == $n"
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"
193 GIT_DIR="$repo" WVPASS git log -n1 --pretty=format:"$fmt" "$hash"
197 WVSTART 'rm /foo/BAR (setup)'
198 WVPASS rm -rf bup bup-baseline src
201 WVPASS echo twisty-maze > src/1
203 WVPASS bup save -n src src
204 WVPASS echo twisty-maze > src/2
207 WVPASS bup save -n src src
208 WVPASS echo twisty-maze > src/3
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
216 WVSTART "rm /foo/BAR (first of many)"
217 WVPASS "$top"/dev/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 $?
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)"
228 WVSTART "rm /foo/BAR (one of many)"
229 WVPASS "$top"/dev/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 $?
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)"
239 WVSTART "rm /foo/BAR (last of many)"
240 WVPASS "$top"/dev/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 $?
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)"
254 # FIXME: test that committer changes when rewriting, when appropriate
256 WVPASS rm -rf "$tmpdir"