From 02f213b831d8e1d4a1d8ebb18d1260571fe20b84 Mon Sep 17 00:00:00 2001 From: Elod Illes Date: Fri, 26 Jun 2020 20:31:20 +0200 Subject: [PATCH] Fix cherry-pick check for merge patch Cherry-pick check script validates the proposed patch's commit message. If a patch is not on top of the given branch then Zuul rebases it to the top and the patch becomes a merge patch. In this case the script validates the merge patch's commit message instead of the original patch's commit message and fails. This fix selects the parent of the patch if it is a merge patch. Change-Id: I8e4e5afc773d53dee9c1c24951bb07a45ddc2f1a (cherry picked from commit c7c48c6f52c9159767b60a4576ba37726156a5f7) --- tools/check-cherry-picks.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tools/check-cherry-picks.sh b/tools/check-cherry-picks.sh index 307837d2aa38..32627e59b605 100755 --- a/tools/check-cherry-picks.sh +++ b/tools/check-cherry-picks.sh @@ -4,7 +4,17 @@ # to verify that they're all on either master or stable/ branches # -hashes=$(git show --format='%b' --quiet $1 | sed -nr 's/^.cherry picked from commit (.*).$/\1/p') +commit_hash="" + +# Check if the patch is a merge patch by counting the number of parents. +# If the patch has 2 parents, then the 2nd parent is the patch we want +# to validate. +parent_number=$(git show --format='%P' --quiet | awk '{print NF}') +if [ $parent_number -eq 2 ]; then + commit_hash=$(git show --format='%P' --quiet | awk '{print $NF}') +fi + +hashes=$(git show --format='%b' --quiet $commit_hash | sed -nr 's/^.cherry picked from commit (.*).$/\1/p') checked=0 branches+="" for hash in $hashes; do