Skip to content

Commit 577f111

Browse files
committed
Make verify-commits.sh test that merges are clean
1 parent 7be9a9a commit 577f111

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)