[tests] Add libFuzzer support.
[bitcoinplatinum.git] / contrib / devtools / git-subtree-check.sh
blob2384d66cad2aa71778b27737629245ab839722da
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 junk; 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 latest_squash="$(find_latest_squash "$DIR")"
45 if [ -z "$latest_squash" ]; then
46 echo "ERROR: $DIR is not a subtree" >&2
47 exit 2
50 set $latest_squash
51 old=$1
52 rev=$2
53 if [ "d$(git cat-file -t $rev 2>/dev/null)" != dcommit ]; then
54 echo "ERROR: subtree commit $rev unavailable. Fetch/update the subtree repository" >&2
55 exit 2
57 tree_subtree=$(git show -s --format="%T" $rev)
58 echo "$DIR in $COMMIT was last updated to upstream commit $rev (tree $tree_subtree)"
59 tree_actual=$(git ls-tree -d "$COMMIT" "$DIR" | head -n 1)
60 if [ -z "$tree_actual" ]; then
61 echo "FAIL: subtree directory $DIR not found in $COMMIT" >&2
62 exit 1
64 set $tree_actual
65 tree_actual_type=$2
66 tree_actual_tree=$3
67 echo "$DIR in $COMMIT currently refers to $tree_actual_type $tree_actual_tree"
68 if [ "d$tree_actual_type" != "dtree" ]; then
69 echo "FAIL: subtree directory $DIR is not a tree in $COMMIT" >&2
70 exit 1
72 if [ "$tree_actual_tree" != "$tree_subtree" ]; then
73 git diff-tree $tree_actual_tree $tree_subtree >&2
74 echo "FAIL: subtree directory tree doesn't match subtree commit tree" >&2
75 exit 1
77 echo "GOOD"