2015-04-03 02:15:29 +02:00
|
|
|
#!/bin/sh
|
2021-12-30 18:36:57 +01:00
|
|
|
# Copyright (c) 2015-2021 The Bitcoin Core developers
|
2016-09-11 21:36:22 +02:00
|
|
|
# Distributed under the MIT software license, see the accompanying
|
|
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2015-04-03 02:15:29 +02:00
|
|
|
|
2018-06-13 16:50:48 +02:00
|
|
|
export LC_ALL=C
|
2020-12-04 09:33:15 +01:00
|
|
|
|
|
|
|
check_remote=0
|
|
|
|
while getopts "?hr" opt; do
|
|
|
|
case $opt in
|
|
|
|
'?' | h)
|
|
|
|
echo "Usage: $0 [-r] DIR [COMMIT]"
|
|
|
|
echo " $0 -?"
|
|
|
|
echo ""
|
|
|
|
echo "Checks that a certain prefix is pure subtree, and optionally whether the"
|
|
|
|
echo "referenced commit is present in any fetched remote."
|
|
|
|
echo ""
|
|
|
|
echo "DIR is the prefix within the repository to check."
|
|
|
|
echo "COMMIT is the commit to check, if it is not provided, HEAD will be used."
|
|
|
|
echo ""
|
|
|
|
echo "-r Check that subtree commit is present in repository."
|
|
|
|
echo " To do this check, fetch the subtreed remote first. Example:"
|
|
|
|
echo ""
|
|
|
|
echo " git fetch https://github.com/bitcoin-core/secp256k1.git"
|
|
|
|
echo " test/lint/git-subtree-check.sh -r src/secp256k1"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
r)
|
|
|
|
check_remote=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $((OPTIND-1))
|
|
|
|
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
echo "Need to provide a DIR, see $0 -?"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-10-31 16:53:46 +01:00
|
|
|
# Strip trailing / from directory path (in case it was added by autocomplete)
|
|
|
|
DIR="${1%/}"
|
2015-04-03 02:15:29 +02:00
|
|
|
COMMIT="$2"
|
|
|
|
if [ -z "$COMMIT" ]; then
|
|
|
|
COMMIT=HEAD
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Taken from git-subtree (Copyright (C) 2009 Avery Pennarun <apenwarr@gmail.com>)
|
|
|
|
find_latest_squash()
|
|
|
|
{
|
|
|
|
dir="$1"
|
|
|
|
sq=
|
|
|
|
main=
|
|
|
|
sub=
|
|
|
|
git log --grep="^git-subtree-dir: $dir/*\$" \
|
|
|
|
--pretty=format:'START %H%n%s%n%n%b%nEND%n' "$COMMIT" |
|
2017-07-08 00:15:36 +02:00
|
|
|
while read a b _; do
|
2015-04-03 02:15:29 +02:00
|
|
|
case "$a" in
|
|
|
|
START) sq="$b" ;;
|
|
|
|
git-subtree-mainline:) main="$b" ;;
|
|
|
|
git-subtree-split:) sub="$b" ;;
|
|
|
|
END)
|
|
|
|
if [ -n "$sub" ]; then
|
|
|
|
if [ -n "$main" ]; then
|
|
|
|
# a rejoin commit?
|
|
|
|
# Pretend its sub was a squash.
|
|
|
|
sq="$sub"
|
|
|
|
fi
|
|
|
|
echo "$sq" "$sub"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
sq=
|
|
|
|
main=
|
|
|
|
sub=
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2017-09-25 03:28:51 +02:00
|
|
|
# find latest subtree update
|
2015-04-03 02:15:29 +02:00
|
|
|
latest_squash="$(find_latest_squash "$DIR")"
|
|
|
|
if [ -z "$latest_squash" ]; then
|
|
|
|
echo "ERROR: $DIR is not a subtree" >&2
|
|
|
|
exit 2
|
|
|
|
fi
|
2021-11-07 13:13:39 +01:00
|
|
|
# shellcheck disable=SC2086
|
2015-04-03 02:15:29 +02:00
|
|
|
set $latest_squash
|
2017-11-09 22:53:09 +01:00
|
|
|
old=$1
|
2015-04-03 02:15:29 +02:00
|
|
|
rev=$2
|
2017-09-25 03:28:51 +02:00
|
|
|
|
|
|
|
# get the tree in the current commit
|
2015-04-03 02:15:29 +02:00
|
|
|
tree_actual=$(git ls-tree -d "$COMMIT" "$DIR" | head -n 1)
|
|
|
|
if [ -z "$tree_actual" ]; then
|
|
|
|
echo "FAIL: subtree directory $DIR not found in $COMMIT" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-11-07 13:13:39 +01:00
|
|
|
# shellcheck disable=SC2086
|
2015-04-03 02:15:29 +02:00
|
|
|
set $tree_actual
|
|
|
|
tree_actual_type=$2
|
|
|
|
tree_actual_tree=$3
|
|
|
|
echo "$DIR in $COMMIT currently refers to $tree_actual_type $tree_actual_tree"
|
|
|
|
if [ "d$tree_actual_type" != "dtree" ]; then
|
|
|
|
echo "FAIL: subtree directory $DIR is not a tree in $COMMIT" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2017-09-25 03:28:51 +02:00
|
|
|
|
|
|
|
# get the tree at the time of the last subtree update
|
2021-11-07 13:13:39 +01:00
|
|
|
tree_commit=$(git show -s --format="%T" "$old")
|
2017-09-25 03:28:51 +02:00
|
|
|
echo "$DIR in $COMMIT was last updated in commit $old (tree $tree_commit)"
|
|
|
|
|
|
|
|
# ... and compare the actual tree with it
|
|
|
|
if [ "$tree_actual_tree" != "$tree_commit" ]; then
|
2021-11-07 13:13:39 +01:00
|
|
|
git diff "$tree_commit" "$tree_actual_tree" >&2
|
2017-09-25 03:28:51 +02:00
|
|
|
echo "FAIL: subtree directory was touched without subtree merge" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-12-04 09:33:15 +01:00
|
|
|
if [ "$check_remote" != "0" ]; then
|
|
|
|
# get the tree in the subtree commit referred to
|
2021-11-07 13:13:39 +01:00
|
|
|
if [ "d$(git cat-file -t "$rev" 2>/dev/null)" != dcommit ]; then
|
2020-12-04 09:33:15 +01:00
|
|
|
echo "subtree commit $rev unavailable: cannot compare. Did you add and fetch the remote?" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-11-07 13:13:39 +01:00
|
|
|
tree_subtree=$(git show -s --format="%T" "$rev")
|
2020-12-04 09:33:15 +01:00
|
|
|
echo "$DIR in $COMMIT was last updated to upstream commit $rev (tree $tree_subtree)"
|
2017-09-25 03:28:51 +02:00
|
|
|
|
2020-12-04 09:33:15 +01:00
|
|
|
# ... and compare the actual tree with it
|
|
|
|
if [ "$tree_actual_tree" != "$tree_subtree" ]; then
|
|
|
|
echo "FAIL: subtree update commit differs from upstream tree!" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-04-03 02:15:29 +02:00
|
|
|
fi
|
2017-09-25 03:28:51 +02:00
|
|
|
|
2015-04-03 02:15:29 +02:00
|
|
|
echo "GOOD"
|