]> arthur.barton.de Git - bup.git/blob - t/git-cat-tree
tclient: invoke bup via absolute path
[bup.git] / t / git-cat-tree
1 #!/usr/bin/env bash
2
3 # Recursively dump all blobs in the subtree identified by ID.
4
5 set -o pipefail
6
7 usage() {
8 cat <<EOF
9 Usage: cat-git-tree ID
10 EOF
11 }
12
13 cat-item()
14 {
15     local hash="$1"
16     local type="$2"
17     case "$type" in
18         blob)
19             git cat-file blob "$hash" || exit $?
20             ;;
21         tree)
22             local tree=$(git ls-tree "$hash") || exit $?
23             while read -r line; do
24                 local sub_type=$(echo "$line" | cut -d' ' -f 2) || exit $?
25                 local sub_hash=$(echo "$line" | cut -d' ' -f 3) || exit $?
26                 sub_hash=$(echo "$sub_hash" | cut -d'   ' -f 1) || exit $?
27                 cat-item "$sub_hash" "$sub_type"
28             done <<< "$tree"
29             ;;
30         *)
31             echo "Unexpected item: $type $hash" 1>&2
32             exit 1
33             ;;
34     esac
35 }
36
37 if test $# -ne 1
38 then
39     usage 1>&2
40     exit 1
41 fi
42
43 top="$1"
44 type=$(git cat-file -t "$top") || exit $?
45 cat-item "$top" "$type"