From ba0dfbae381cc6de952e7e4351595bb705530909 Mon Sep 17 00:00:00 2001 From: Oscar Vestlie Date: Tue, 14 Nov 2023 13:19:32 -0800 Subject: [PATCH] more fixes --- .github/workflows/label-cherry-pick.yaml | 33 ++++++++++++++---------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/.github/workflows/label-cherry-pick.yaml b/.github/workflows/label-cherry-pick.yaml index 8f08f846adf0a..0b75d93f388b8 100644 --- a/.github/workflows/label-cherry-pick.yaml +++ b/.github/workflows/label-cherry-pick.yaml @@ -82,24 +82,29 @@ jobs: run: | git fetch origin ${{ matrix.target_branch }} set +e - git cherry-pick -x ${MERGE_COMMIT_SHA} - RES=$? - if [ $RES -ne 0 ]; then - # If the cherry pick failed due to a merge conflict we can - # add the conflicting file and create the commit anyway. - git add . - git cherry-pick --continue + + rev_list=`git rev-list --parents -n 1 ${MERGE_COMMIT_SHA}` + hash_count=`wc -w <<< ${rev_list}` + + # git rev-list returns a list of hashes: [...] + # It's not a merge commit if there are less than three (i.e. less than two parents). + if [ ${hash_count} -lt 3 ]; then + git cherry-pick -x ${MERGE_COMMIT_SHA} RES=$? - # If the cherry pick fails again it could be a merge commit. - # Try to select the first parent (-m 1) as the mainline tree. - if [ $RES -ne 0 ]; then - git cherry-pick -x -m 1 ${MERGE_COMMIT_SHA} - RES=$? + if [ ${RES} -ne 0 ]; then + # If the cherry pick failed due to a merge conflict we can + # add the conflicting file and create the commit anyway. + git add . + git cherry-pick --continue + exit $? fi + else + # This commit is a merge commit and has multiple parents. + # Select the first parent (-m 1) as the mainline tree. + git cherry-pick -x -m 1 ${MERGE_COMMIT_SHA} + RES=$? fi - set -e - exit $RES - name: Create Pull Request id: create-pr