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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
|
#!/usr/bin/env bash
. ./wvtest-bup.sh || exit $?
. ./dev/lib.sh || exit $?
top="$(WVPASS pwd)" || exit $?
tmpdir="$(WVPASS wvmktempdir)" || exit $?
export BUP_DIR="$tmpdir/bup"
export GIT_DIR="$tmpdir/bup"
bup() { "$top/bup" "$@"; }
compare-trees() { "$top/dev/compare-trees" "$@"; }
wv_matches_rx()
{
local caller_file=${BASH_SOURCE[0]}
local caller_line=${BASH_LINENO[0]}
local src="$caller_file:$caller_line"
if test $# -ne 2; then
echo "! $src wv_matches_rx requires 2 arguments FAILED" 1>&2
return
fi
local str="$1"
local rx="$2"
echo "Matching:" 1>&2 || exit $?
echo "$str" | sed 's/^\(.*\)/ \1/' 1>&2 || exit $?
echo "Against:" 1>&2 || exit $?
echo "$rx" | sed 's/^\(.*\)/ \1/' 1>&2 || exit $?
if [[ "$str" =~ ^${rx}$ ]]; then
echo "! $src regex matches ok" 1>&2 || exit $?
else
echo "! $src regex doesn't match FAILED" 1>&2 || exit $?
fi
}
WVPASS bup init
WVPASS cd "$tmpdir"
WVSTART "rm /foo (lone branch)"
WVPASS mkdir src src/foo
WVPASS echo twisty-maze > src/1
WVPASS bup index src
WVPASS bup save -n src src
WVPASS "$top"/dev/sync-tree bup/ bup-baseline/
# FIXME: test -n
WVPASS bup tick # Make sure we always get the timestamp changes below
WVPASS bup rm --unsafe /src
observed="$(compare-trees bup/ bup-baseline/ | LC_ALL=C sort)" || exit $?
wv_matches_rx "$observed" \
'\*deleting[ ]+logs/refs/heads/src
\*deleting[ ]+refs/heads/src(
\.d\.\.t\.\.\.[.]*[ ]+\./)?
\.d\.\.t\.\.\.[.]*[ ]+logs/refs/heads/
\.d\.\.t\.\.\.[.]*[ ]+refs/heads/(
>f\+\+\+\+\+\+\+\+\+[ ]+packed-refs)?'
WVSTART "rm /foo (one of many)"
WVPASS rm -rf bup
WVPASS mv bup-baseline bup
WVPASS echo twisty-maze > src/2
WVPASS bup index src
WVPASS bup save -n src-2 src
WVPASS echo twisty-maze > src/3
WVPASS bup index src
WVPASS bup save -n src-3 src
WVPASS "$top"/dev/sync-tree bup/ bup-baseline/
WVPASS bup tick # Make sure we always get the timestamp changes below
WVPASS bup rm --unsafe /src
observed="$(compare-trees bup/ bup-baseline/ | LC_ALL=C sort)" || exit $?
wv_matches_rx "$observed" \
"\*deleting[ ]+logs/refs/heads/src
\*deleting[ ]+refs/heads/src(
\.d\.\.t\.\.\.[.]*[ ]+\./)?
\.d\.\.t\.\.\.[.]*[ ]+logs/refs/heads/
\.d\.\.t\.\.\.[.]*[ ]+refs/heads/(
>f\+\+\+\+\+\+\+\+\+[ ]+packed-refs)?"
WVSTART "rm /foo /bar (multiple of many)"
WVPASS rm -rf bup
WVPASS mv bup-baseline bup
WVPASS echo twisty-maze > src/4
WVPASS bup index src
WVPASS bup save -n src-4 src
WVPASS echo twisty-maze > src/5
WVPASS bup index src
WVPASS bup save -n src-5 src
WVPASS "$top"/dev/sync-tree bup/ bup-baseline/
WVPASS bup tick # Make sure we always get the timestamp changes below
WVPASS bup rm --unsafe /src-2 /src-4
observed="$(compare-trees bup/ bup-baseline/ | LC_ALL=C sort)" || exit $?
wv_matches_rx "$observed" \
"\*deleting[ ]+logs/refs/heads/src-2
\*deleting[ ]+logs/refs/heads/src-4
\*deleting[ ]+refs/heads/src-2
\*deleting[ ]+refs/heads/src-4(
\.d\.\.t\.\.\.[.]*[ ]+\./)?
\.d\.\.t\.\.\.[.]*[ ]+logs/refs/heads/
\.d\.\.t\.\.\.[.]*[ ]+refs/heads/(
>f\+\+\+\+\+\+\+\+\+[ ]+packed-refs)?"
WVSTART "rm /foo /bar (all)"
WVPASS rm -rf bup
WVPASS mv bup-baseline bup
WVPASS "$top"/dev/sync-tree bup/ bup-baseline/
WVPASS bup tick # Make sure we always get the timestamp changes below
WVPASS bup rm --unsafe /src /src-2 /src-3 /src-4 /src-5
observed="$(compare-trees bup/ bup-baseline/ | LC_ALL=C sort)" || exit $?
wv_matches_rx "$observed" \
"\*deleting[ ]+logs/refs/heads/src
\*deleting[ ]+logs/refs/heads/src-2
\*deleting[ ]+logs/refs/heads/src-3
\*deleting[ ]+logs/refs/heads/src-4
\*deleting[ ]+logs/refs/heads/src-5
\*deleting[ ]+refs/heads/src
\*deleting[ ]+refs/heads/src-2
\*deleting[ ]+refs/heads/src-3
\*deleting[ ]+refs/heads/src-4
\*deleting[ ]+refs/heads/src-5(
\.d\.\.t\.\.\.[.]*[ ]+\./)?
\.d\.\.t\.\.\.[.]*[ ]+logs/refs/heads/
\.d\.\.t\.\.\.[.]*[ ]+refs/heads/(
>f\+\+\+\+\+\+\+\+\+[ ]+packed-refs)?"
WVSTART "rm /foo/bar (lone save - equivalent to rm /foo)"
WVPASS rm -rf bup bup-baseline src
WVPASS bup init
WVPASS mkdir src
WVPASS echo twisty-maze > src/1
WVPASS bup index src
WVPASS bup save -n src src
WVPASS bup ls src > tmp-ls
save1="$(WVPASS head -n 1 tmp-ls)" || exit $?
WVPASS "$top"/dev/sync-tree bup/ bup-baseline/
WVPASS bup tick # Make sure we always get the timestamp changes below
WVFAIL bup rm --unsafe /src/latest
WVPASS bup rm --unsafe /src/"$save1"
observed="$(compare-trees bup/ bup-baseline/ | LC_ALL=C sort)" || exit $?
wv_matches_rx "$observed" \
"\*deleting[ ]+logs/refs/heads/src
\*deleting[ ]+refs/heads/src(
\.d\.\.t\.\.\.[.]*[ ]+\./)?
\.d\.\.t\.\.\.[.]*[ ]+logs/refs/heads/
\.d\.\.t\.\.\.[.]*[ ]+refs/heads/(
>f\+\+\+\+\+\+\+\+\+[ ]+packed-refs)?"
verify-changes-caused-by-rewriting-save()
{
local before="$1" after="$2" tmpdir
tmpdir="$(WVPASS wvmktempdir)" || exit $?
(WVPASS cd "$before" && WVPASS find . | WVPASS sort) \
> "$tmpdir/before" || exit $?
(WVPASS cd "$after" && WVPASS find . | WVPASS sort) \
> "$tmpdir/after" || exit $?
local new_paths new_idx new_pack observed
new_paths="$(WVPASS comm -13 "$tmpdir/before" "$tmpdir/after")" || exit $?
new_idx="$(echo "$new_paths" | WVPASS grep -E '^\./objects/pack/pack-.*\.idx$' | cut -b 3-)" || exit $?
new_pack="$(echo "$new_paths" | WVPASS grep -E '^\./objects/pack/pack-.*\.pack$' | cut -b 3-)" || exit $?
wv_matches_rx "$(compare-trees "$after/" "$before/")" \
">fcst\.\.\.[.]*[ ]+logs/refs/heads/src
\.d\.\.t\.\.\.[.]*[ ]+objects/
\.d\.\.t\.\.\.[.]*[ ]+objects/pack/
>fcst\.\.\.[.]*[ ]+objects/pack/bup\.bloom
>f\+\+\+\+\+\+\+[+]*[ ]+$new_idx
>f\+\+\+\+\+\+\+[+]*[ ]+$new_pack
\.d\.\.t\.\.\.[.]*[ ]+refs/heads/
>fc\.t\.\.\.[.]*[ ]+refs/heads/src"
WVPASS rm -rf "$tmpdir"
}
commit-hash-n()
{
local n="$1" repo="$2" branch="$3"
GIT_DIR="$repo" WVPASS git rev-list --reverse "$branch" \
| WVPASS awk "FNR == $n"
}
rm-safe-cinfo()
{
local n="$1" repo="$2" branch="$3" hash
hash="$(commit-hash-n "$n" "$repo" "$branch")" || exit $?
local fmt='Tree: %T%n'
fmt="${fmt}Author: %an <%ae> %ai%n"
fmt="${fmt}Committer: %cn <%ce> %ci%n"
fmt="${fmt}%n%s%n%b"
GIT_DIR="$repo" WVPASS git log -n1 --pretty=format:"$fmt" "$hash"
}
WVSTART 'rm /foo/BAR (setup)'
WVPASS rm -rf bup bup-baseline src
WVPASS bup init
WVPASS mkdir src
WVPASS echo twisty-maze > src/1
WVPASS bup index src
WVPASS bup save -n src src
WVPASS echo twisty-maze > src/2
WVPASS bup index src
WVPASS bup tick
WVPASS bup save -n src src
WVPASS echo twisty-maze > src/3
WVPASS bup index src
WVPASS bup tick
WVPASS bup save -n src src
WVPASS mv bup bup-baseline
WVPASS bup tick # Make sure we always get the timestamp changes below
WVSTART "rm /foo/BAR (first of many)"
WVPASS "$top"/dev/sync-tree bup-baseline/ bup/
WVPASS bup ls src > tmp-ls
victim="$(WVPASS head -n 1 tmp-ls)" || exit $?
WVPASS bup rm --unsafe /src/"$victim"
verify-changes-caused-by-rewriting-save bup-baseline bup
observed=$(WVPASS git rev-list src | WVPASS wc -l) || exit $?
WVPASSEQ 2 $observed
WVPASSEQ "$(rm-safe-cinfo 1 bup src)" "$(rm-safe-cinfo 2 bup-baseline src)"
WVPASSEQ "$(rm-safe-cinfo 2 bup src)" "$(rm-safe-cinfo 3 bup-baseline src)"
WVSTART "rm /foo/BAR (one of many)"
WVPASS "$top"/dev/sync-tree bup-baseline/ bup/
victim="$(WVPASS bup ls src | tail -n +2 | head -n 1)" || exit $?
WVPASS bup rm --unsafe /src/"$victim"
verify-changes-caused-by-rewriting-save bup-baseline bup
observed=$(git rev-list src | wc -l) || exit $?
WVPASSEQ 2 $observed
WVPASSEQ "$(commit-hash-n 1 bup src)" "$(commit-hash-n 1 bup-baseline src)"
WVPASSEQ "$(rm-safe-cinfo 2 bup src)" "$(rm-safe-cinfo 3 bup-baseline src)"
WVSTART "rm /foo/BAR (last of many)"
WVPASS "$top"/dev/sync-tree bup-baseline/ bup/
victim="$(WVPASS bup ls src | tail -n 2 | head -n 1)" || exit $?
WVPASS bup rm --unsafe -vv /src/"$victim"
observed="$(compare-trees bup/ bup-baseline/ | LC_ALL=C sort)" || exit $?
wv_matches_rx "$observed" \
"\.d\.\.t\.\.\.[.]*[ ]+refs/heads/
>fc\.t\.\.\.[.]*[ ]+refs/heads/src
>fcst\.\.\.[.]*[ ]+logs/refs/heads/src"
observed=$(git rev-list src | wc -l) || exit $?
WVPASSEQ 2 $observed
WVPASSEQ "$(commit-hash-n 1 bup src)" "$(commit-hash-n 1 bup-baseline src)"
WVPASSEQ "$(commit-hash-n 2 bup src)" "$(commit-hash-n 2 bup-baseline src)"
# FIXME: test that committer changes when rewriting, when appropriate
WVPASS rm -rf "$tmpdir"
|