]> arthur.barton.de Git - bup.git/blob - t/compare-trees
Move tree comparison to t/compare-trees; compare content by default.
[bup.git] / t / compare-trees
1 #!/usr/bin/env bash
2
3 # Test that src and dest trees are as identical as bup is capable of
4 # making them.  For now, use rsync -niaHAX ...
5
6 set -e
7 set -o pipefail
8
9 usage() {
10 cat <<EOF
11 Usage: compare-trees [-h] [-c] [-x] SOURCE DEST
12 OPTIONS:
13   -h
14     Display help
15   -c
16     Check file content (default)
17   -x
18     Don't check file content (rely on size/timestamps, etc.)
19 EOF
20 }
21
22 verify_content=" --checksum"
23
24 while getopts "hc" OPTION
25 do
26     case "$OPTION" in
27         h) usage; exit 0;;
28         c) verify_content=" --checksum";;
29         x) verify_content="";;
30         ?) usage 1>&2; exit 1;;
31     esac
32 done
33
34 shift $(($OPTIND - 1))
35
36 if ! test $# -eq 2
37 then
38     usage 1>&2
39     exit 1
40 fi
41
42 src="$1"
43 dest="$2"
44
45 tmpfile="$(mktemp)"
46 trap "rm -rf '${tmpfile}'" EXIT
47
48 rsync -niaHAX$verify_content --delete "$src" "$dest" > "${tmpfile}"
49 if test $(wc -l < "${tmpfile}") != 0; then
50     echo "Differences between $src and $dest"
51     cat "${tmpfile}"
52     exit 1
53 fi
54
55 exit 0