]> arthur.barton.de Git - bup.git/blob - t/test-redundant-saves.sh
145994ad3fa70571514518819ea774019b5ca4a7
[bup.git] / t / test-redundant-saves.sh
1 #!/usr/bin/env bash
2
3 # Test that running save more than once with no other changes produces
4 # the exact same tree.
5
6 # Note: we can't compare the top-level hash (i.e. the output of "save
7 # -t" because that currently pulls the metadata for unindexed parent
8 # directories directly from the filesystem, and the relevant atimes
9 # may change between runs.  So instead we extract the roots of the
10 # indexed trees for comparison via t/subtree-hash.
11
12 . ./wvtest-bup.sh
13
14 WVSTART 'all'
15
16 top="$(pwd)"
17 tmpdir="$(WVPASS wvmktempdir)" || exit $?
18
19 export BUP_DIR="$tmpdir/bup"
20 export GIT_DIR="$BUP_DIR"
21
22 bup() { "$top/bup" "$@"; }
23
24 WVPASS mkdir -p "$tmpdir/src"
25 WVPASS mkdir -p "$tmpdir/src/d"
26 WVPASS mkdir -p "$tmpdir/src/d/e"
27 WVPASS touch "$tmpdir/src/"{f,b,a,d}
28 WVPASS touch "$tmpdir/src/d/z"
29
30 WVPASS bup init
31 WVPASS bup index -u "$tmpdir/src"
32
33 declare -a indexed_top
34 IFS=/
35 indexed_top="${tmpdir##/}"
36 indexed_top=(${indexed_top%%/})
37 unset IFS
38
39 tree1=$(WVPASS bup save -t "$tmpdir/src") || exit $?
40 indexed_tree1="$(WVPASS t/subtree-hash "$tree1" "${indexed_top[@]}" src)" \
41     || exit $?
42
43 result="$(WVPASS cd "$tmpdir/src"; WVPASS bup index -m)" || exit $?
44 WVPASSEQ "$result" ""
45
46 tree2=$(WVPASS bup save -t "$tmpdir/src") || exit $?
47 indexed_tree2="$(WVPASS t/subtree-hash "$tree2" "${indexed_top[@]}" src)" \
48     || exit $?
49
50 WVPASSEQ "$indexed_tree1" "$indexed_tree2"
51
52 result="$(WVPASS bup index -s / | WVFAIL grep ^D)" || exit $?
53 WVPASSEQ "$result" ""
54
55 tree3=$(WVPASS bup save -t /) || exit $?
56 indexed_tree3="$(WVPASS t/subtree-hash "$tree3" "${indexed_top[@]}" src)" || exit $?
57 WVPASSEQ "$indexed_tree1" "$indexed_tree3"
58
59 WVPASS rm -rf "$tmpdir"