]> arthur.barton.de Git - bup.git/blob - t/subtree-hash
Avoid uid/gid 0 metadata tests when ids don't exist
[bup.git] / t / subtree-hash
1 #!/usr/bin/env bash
2
3 # Usage: subtree-hash ROOT_HASH [SUBDIR ...]
4
5 subtree_hash()
6 {
7     root_hash="$1"
8     if test "$#" -eq 1; then
9         echo $root_hash
10     else
11         subdir="$2"
12         subtree_info="$(git ls-tree "$root_hash" | grep -E "    $subdir\$")" || true
13         if test "$(echo "$subtree_info" | wc -l)" -ne 1; then
14             echo "Didn't find just one matching line in subtree $root_hash" 1>&2
15             return 1
16         fi
17
18         subtree_hash="$(echo "$subtree_info" | cut -d' ' -f 3 | cut -d$'\t' -f 1)" || true
19         if test -z "$subtree_hash"; then
20             echo "Unable to find subtree hash in git output: $subtree_info" 1>&2
21             return 1
22         fi
23
24         shift 2 || exit $?
25         subtree_hash "$subtree_hash" "$@" || exit $?
26     fi
27 }
28
29 subtree_hash "$@"