Skip to content

Commit b2e5fe8

Browse files
committed
Merge #12708: Make verify-commits.sh test that merges are clean
577f111 Make verify-commits.sh test that merges are clean (Pieter Wuille) Pull request description: Unsure if we want this. This modifies verify-commits.sh to redo all merges along the leftmost commit branch (which includes all PR merges), and verify whether they match the merge commit's trees. The benefit is that it will detect a case where one of the maintainers merges a PR, but makes an unrelated change inside the merge commit. This on itself is not very strong, as unrelated changes can also be included in the merged branch itself - but perhaps the merge commit is not something that people are otherwise likely to look at. Fixes #8089 Tree-SHA512: 2c020f5ac3f771ac775aa726832916bb8e03a311b2745d7a9825047239bd0660d838f086f3456f2bb05cea14c1529f74436b8cdd74cc94b70e40b4617309f62c
2 parents f8d6dc4 + 577f111 commit b2e5fe8

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

contrib/verify-commits/verify-commits.sh

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ NO_SHA1=1
3535
PREV_COMMIT=""
3636
INITIAL_COMMIT="${CURRENT_COMMIT}"
3737

38+
BRANCH="$(git rev-parse --abbrev-ref HEAD)"
39+
3840
while true; do
3941
if [ "$CURRENT_COMMIT" = $VERIFIED_ROOT ]; then
4042
echo "There is a valid path from \"$INITIAL_COMMIT\" to $VERIFIED_ROOT where all commits are signed!"
@@ -123,9 +125,29 @@ while true; do
123125
fi
124126

125127
PARENTS=$(git show -s --format=format:%P "$CURRENT_COMMIT")
126-
for PARENT in $PARENTS; do
127-
PREV_COMMIT="$CURRENT_COMMIT"
128-
CURRENT_COMMIT="$PARENT"
129-
break
130-
done
128+
PARENT1=${PARENTS%% *}
129+
PARENT2=""
130+
if [ "x$PARENT1" != "x$PARENTS" ]; then
131+
PARENTX=${PARENTS#* }
132+
PARENT2=${PARENTX%% *}
133+
if [ "x$PARENT2" != "x$PARENTX" ]; then
134+
echo "Commit $CURRENT_COMMIT is an octopus merge" > /dev/stderr
135+
exit 1
136+
fi
137+
fi
138+
if [ "x$PARENT2" != "x" ]; then
139+
CURRENT_TREE="$(git show --format="%T" "$CURRENT_COMMIT")"
140+
git checkout --force --quiet "$PARENT1"
141+
git merge --no-ff --quiet "$PARENT2" >/dev/null
142+
RECREATED_TREE="$(git show --format="%T" HEAD)"
143+
if [ "$CURRENT_TREE" != "$RECREATED_TREE" ]; then
144+
echo "Merge commit $CURRENT_COMMIT is not clean" > /dev/stderr
145+
git diff "$CURRENT_COMMIT"
146+
git checkout --force --quiet "$BRANCH"
147+
exit 1
148+
fi
149+
git checkout --force --quiet "$BRANCH"
150+
fi
151+
PREV_COMMIT="$CURRENT_COMMIT"
152+
CURRENT_COMMIT="$PARENT1"
131153
done

0 commit comments

Comments
 (0)