]> arthur.barton.de Git - bup.git/blob - t/subtree-hash
Be more careful when testing that repeated saves can produce the same tree.
[bup.git] / t / subtree-hash
1 #!/usr/bin/env bash
2
3 set -eo pipefail
4
5 # Usage: subtree-hash ROOT_HASH [SUBDIR ...]
6
7 subtree_hash()
8 {
9     root_hash="$1"
10     if test "$#" -eq 1; then
11         echo $root_hash
12     else
13         subdir="$2"
14         subtree_info="$(git ls-tree "$root_hash" | grep -E "    $subdir\$")" || true
15         if test "$(echo "$subtree_info" | wc -l)" -ne 1; then
16             echo "Found more than one matching line in subtree $root_hash" 1>&2
17             return 1
18         fi
19
20         subtree_hash="$(echo "$subtree_info" | cut -d' ' -f 3 | cut -d$'\t' -f 1)" || true
21         if test -z "$subtree_hash"; then
22             echo "Unable to find subtree hash in git output: $subtree_info" 1>&2
23             return 1
24         fi
25
26         shift 2
27         subtree_hash "$subtree_hash" "$@"
28     fi
29 }
30
31 subtree_hash "$@"