Merge #12079: Improve prioritisetransaction test coverage
[bitcoinplatinum.git] / contrib / devtools / git-subtree-check.sh
blob184951715e99ee051cea0f73535330f5033ee80f
1 #!/bin/sh
2 # Copyright (c) 2015 The Bitcoin Core developers
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 DIR="$1"
7 COMMIT="$2"
8 if [ -z "$COMMIT" ]; then
9 COMMIT=HEAD
12 # Taken from git-subtree (Copyright (C) 2009 Avery Pennarun <apenwarr@gmail.com>)
13 find_latest_squash()
15 dir="$1"
16 sq=
17 main=
18 sub=
19 git log --grep="^git-subtree-dir: $dir/*\$" \
20 --pretty=format:'START %H%n%s%n%n%b%nEND%n' "$COMMIT" |
21 while read a b _; do
22 case "$a" in
23 START) sq="$b" ;;
24 git-subtree-mainline:) main="$b" ;;
25 git-subtree-split:) sub="$b" ;;
26 END)
27 if [ -n "$sub" ]; then
28 if [ -n "$main" ]; then
29 # a rejoin commit?
30 # Pretend its sub was a squash.
31 sq="$sub"
33 echo "$sq" "$sub"
34 break
36 sq=
37 main=
38 sub=
40 esac
41 done
44 # find latest subtree update
45 latest_squash="$(find_latest_squash "$DIR")"
46 if [ -z "$latest_squash" ]; then
47 echo "ERROR: $DIR is not a subtree" >&2
48 exit 2
50 set $latest_squash
51 old=$1
52 rev=$2
54 # get the tree in the current commit
55 tree_actual=$(git ls-tree -d "$COMMIT" "$DIR" | head -n 1)
56 if [ -z "$tree_actual" ]; then
57 echo "FAIL: subtree directory $DIR not found in $COMMIT" >&2
58 exit 1
60 set $tree_actual
61 tree_actual_type=$2
62 tree_actual_tree=$3
63 echo "$DIR in $COMMIT currently refers to $tree_actual_type $tree_actual_tree"
64 if [ "d$tree_actual_type" != "dtree" ]; then
65 echo "FAIL: subtree directory $DIR is not a tree in $COMMIT" >&2
66 exit 1
69 # get the tree at the time of the last subtree update
70 tree_commit=$(git show -s --format="%T" $old)
71 echo "$DIR in $COMMIT was last updated in commit $old (tree $tree_commit)"
73 # ... and compare the actual tree with it
74 if [ "$tree_actual_tree" != "$tree_commit" ]; then
75 git diff $tree_commit $tree_actual_tree >&2
76 echo "FAIL: subtree directory was touched without subtree merge" >&2
77 exit 1
80 # get the tree in the subtree commit referred to
81 if [ "d$(git cat-file -t $rev 2>/dev/null)" != dcommit ]; then
82 echo "subtree commit $rev unavailable: cannot compare" >&2
83 exit
85 tree_subtree=$(git show -s --format="%T" $rev)
86 echo "$DIR in $COMMIT was last updated to upstream commit $rev (tree $tree_subtree)"
88 # ... and compare the actual tree with it
89 if [ "$tree_actual_tree" != "$tree_subtree" ]; then
90 echo "FAIL: subtree update commit differs from upstream tree!" >&2
91 exit 1
94 echo "GOOD"