Changeset View
Changeset View
Standalone View
Standalone View
test/lint/git-subtree-check.sh
Show All 35 Lines | case "$a" in | ||||
sq= | sq= | ||||
main= | main= | ||||
sub= | sub= | ||||
;; | ;; | ||||
esac | esac | ||||
done | done | ||||
} | } | ||||
# find latest subtree update | |||||
latest_squash="$(find_latest_squash "$DIR")" | latest_squash="$(find_latest_squash "$DIR")" | ||||
if [ -z "$latest_squash" ]; then | if [ -z "$latest_squash" ]; then | ||||
echo "ERROR: $DIR is not a subtree" >&2 | echo "ERROR: $DIR is not a subtree" >&2 | ||||
exit 2 | exit 2 | ||||
fi | fi | ||||
set $latest_squash | set $latest_squash | ||||
old=$1 | old=$1 | ||||
rev=$2 | rev=$2 | ||||
if [ "d$(git cat-file -t $rev 2>/dev/null)" != dcommit ]; then | |||||
echo "ERROR: subtree commit $rev unavailable. Fetch/update the subtree repository" >&2 | # get the tree in the current commit | ||||
exit 2 | |||||
fi | |||||
tree_subtree=$(git show -s --format="%T" $rev) | |||||
echo "$DIR in $COMMIT was last updated to upstream commit $rev (tree $tree_subtree)" | |||||
tree_actual=$(git ls-tree -d "$COMMIT" "$DIR" | head -n 1) | tree_actual=$(git ls-tree -d "$COMMIT" "$DIR" | head -n 1) | ||||
if [ -z "$tree_actual" ]; then | if [ -z "$tree_actual" ]; then | ||||
echo "FAIL: subtree directory $DIR not found in $COMMIT" >&2 | echo "FAIL: subtree directory $DIR not found in $COMMIT" >&2 | ||||
exit 1 | exit 1 | ||||
fi | fi | ||||
set $tree_actual | set $tree_actual | ||||
tree_actual_type=$2 | tree_actual_type=$2 | ||||
tree_actual_tree=$3 | tree_actual_tree=$3 | ||||
echo "$DIR in $COMMIT currently refers to $tree_actual_type $tree_actual_tree" | echo "$DIR in $COMMIT currently refers to $tree_actual_type $tree_actual_tree" | ||||
if [ "d$tree_actual_type" != "dtree" ]; then | if [ "d$tree_actual_type" != "dtree" ]; then | ||||
echo "FAIL: subtree directory $DIR is not a tree in $COMMIT" >&2 | echo "FAIL: subtree directory $DIR is not a tree in $COMMIT" >&2 | ||||
exit 1 | exit 1 | ||||
fi | fi | ||||
# get the tree at the time of the last subtree update | |||||
tree_commit=$(git show -s --format="%T" $old) | |||||
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 | |||||
git diff $tree_commit $tree_actual_tree >&2 | |||||
echo "FAIL: subtree directory was touched without subtree merge" >&2 | |||||
exit 1 | |||||
fi | |||||
# get the tree in the subtree commit referred to | |||||
if [ "d$(git cat-file -t $rev 2>/dev/null)" != dcommit ]; then | |||||
echo "subtree commit $rev unavailable: cannot compare" >&2 | |||||
exit | |||||
fi | |||||
tree_subtree=$(git show -s --format="%T" $rev) | |||||
echo "$DIR in $COMMIT was last updated to upstream commit $rev (tree $tree_subtree)" | |||||
# ... and compare the actual tree with it | |||||
if [ "$tree_actual_tree" != "$tree_subtree" ]; then | if [ "$tree_actual_tree" != "$tree_subtree" ]; then | ||||
git diff-tree $tree_actual_tree $tree_subtree >&2 | echo "FAIL: subtree update commit differs from upstream tree!" >&2 | ||||
echo "FAIL: subtree directory tree doesn't match subtree commit tree" >&2 | |||||
exit 1 | exit 1 | ||||
fi | fi | ||||
echo "GOOD" | echo "GOOD" |