Skip to content

Commit 0a957fb

Browse files
ci: leave comment and abort early if commit already exists on target branch in backport workflow (#6326)
Follow up on #6317: Fixes confusing "merge conflicts detected" message when commit already exists on target branch (e.g., PRs #6294 and #6307). ## Changes - Added check to detect if merge commit already exists on target branch before attempting cherry-pick - New failure reason `already-exists` for this case - Clear comment message: "Commit already exists on branch, no backport needed" instead of confusing "Merge conflicts detected" with empty file list ## Before When a commit already existed on the target branch, users would see: > @user Backport to `core/1.30` failed: Merge conflicts detected. > Please manually cherry-pick commit `abc123` to the `core/1.30` branch. > <details><summary>Conflicting files</summary> > > </details> This was confusing because there were no actual conflicts - the commit was already present. ## After Users now see: > @user Commit `abc123` already exists on branch `core/1.30`. No backport needed. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-6326-ci-leave-comment-and-abort-early-if-commit-already-exists-on-target-branch-in-backport-w-2996d73d36508167aff3e6783e832c74) by [Unito](https://www.unito.io)
1 parent 28a6089 commit 0a957fb

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

.github/workflows/pr-backport.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,14 @@ jobs:
234234
continue
235235
fi
236236
237+
# Check if commit already exists on target branch
238+
if git branch -r --contains "${MERGE_COMMIT}" | grep -q "origin/${TARGET_BRANCH}"; then
239+
echo "::notice::Commit ${MERGE_COMMIT} already exists on ${TARGET_BRANCH}, skipping backport"
240+
FAILED="${FAILED}${TARGET_BRANCH}:already-exists "
241+
echo "::endgroup::"
242+
continue
243+
fi
244+
237245
# Create backport branch
238246
git checkout -b "${BACKPORT_BRANCH}" "origin/${TARGET_BRANCH}"
239247
@@ -328,6 +336,9 @@ jobs:
328336
if [ "${reason}" = "branch-missing" ]; then
329337
gh pr comment "${PR_NUMBER}" --body "@${PR_AUTHOR} Backport failed: Branch \`${target}\` does not exist"
330338
339+
elif [ "${reason}" = "already-exists" ]; then
340+
gh pr comment "${PR_NUMBER}" --body "@${PR_AUTHOR} Commit \`${MERGE_COMMIT}\` already exists on branch \`${target}\`. No backport needed."
341+
331342
elif [ "${reason}" = "conflicts" ]; then
332343
# Convert comma-separated conflicts back to newlines for display
333344
CONFLICTS_LIST=$(echo "${conflicts}" | tr ',' '\n' | sed 's/^/- /')

0 commit comments

Comments
 (0)