Skip to content

Commit e1d0cc2

Browse files
committed
Improve git-subtree-check.sh
We have several pieces of information about subtrees: 1) What their current directory contents is 2) What their directory contents was at the time of the last subtree merge 3) What the directory contents of the upstream project is in the commit referred to by the subtree merge. Normally, all 3 should be identical. git-subtree-check.sh so far only compared (1) with (3) however. Fix this by comparing all three, and give some more useful diff output in the case of mismatch. The added benefit is that (1) and (2) can be compared without needing to see the upstream repository.
1 parent 8928093 commit e1d0cc2

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

contrib/devtools/git-subtree-check.sh

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,17 @@ find_latest_squash()
4141
done
4242
}
4343

44+
# find latest subtree update
4445
latest_squash="$(find_latest_squash "$DIR")"
4546
if [ -z "$latest_squash" ]; then
4647
echo "ERROR: $DIR is not a subtree" >&2
4748
exit 2
4849
fi
49-
5050
set $latest_squash
5151
old=$1
5252
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
56-
fi
57-
tree_subtree=$(git show -s --format="%T" $rev)
58-
echo "$DIR in $COMMIT was last updated to upstream commit $rev (tree $tree_subtree)"
53+
54+
# get the tree in the current commit
5955
tree_actual=$(git ls-tree -d "$COMMIT" "$DIR" | head -n 1)
6056
if [ -z "$tree_actual" ]; then
6157
echo "FAIL: subtree directory $DIR not found in $COMMIT" >&2
@@ -69,9 +65,30 @@ if [ "d$tree_actual_type" != "dtree" ]; then
6965
echo "FAIL: subtree directory $DIR is not a tree in $COMMIT" >&2
7066
exit 1
7167
fi
68+
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)"
72+
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
78+
fi
79+
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
84+
fi
85+
tree_subtree=$(git show -s --format="%T" $rev)
86+
echo "$DIR in $COMMIT was last updated to upstream commit $rev (tree $tree_subtree)"
87+
88+
# ... and compare the actual tree with it
7289
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
90+
echo "FAIL: subtree update commit differs from upstream tree!" >&2
7591
exit 1
7692
fi
93+
7794
echo "GOOD"

0 commit comments

Comments
 (0)