From 0a957fb2ac791d212bb470c0d6156fdbd62337d5 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Sun, 26 Oct 2025 23:37:22 -0700 Subject: [PATCH] ci: leave comment and abort early if commit already exists on target branch in backport workflow (#6326) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow up on https://github.com/Comfy-Org/ComfyUI_frontend/pull/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. >
Conflicting files > >
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) --- .github/workflows/pr-backport.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/pr-backport.yaml b/.github/workflows/pr-backport.yaml index 0275d1b62..8729c5d57 100644 --- a/.github/workflows/pr-backport.yaml +++ b/.github/workflows/pr-backport.yaml @@ -234,6 +234,14 @@ jobs: continue fi + # Check if commit already exists on target branch + if git branch -r --contains "${MERGE_COMMIT}" | grep -q "origin/${TARGET_BRANCH}"; then + echo "::notice::Commit ${MERGE_COMMIT} already exists on ${TARGET_BRANCH}, skipping backport" + FAILED="${FAILED}${TARGET_BRANCH}:already-exists " + echo "::endgroup::" + continue + fi + # Create backport branch git checkout -b "${BACKPORT_BRANCH}" "origin/${TARGET_BRANCH}" @@ -328,6 +336,9 @@ jobs: if [ "${reason}" = "branch-missing" ]; then gh pr comment "${PR_NUMBER}" --body "@${PR_AUTHOR} Backport failed: Branch \`${target}\` does not exist" + elif [ "${reason}" = "already-exists" ]; then + gh pr comment "${PR_NUMBER}" --body "@${PR_AUTHOR} Commit \`${MERGE_COMMIT}\` already exists on branch \`${target}\`. No backport needed." + elif [ "${reason}" = "conflicts" ]; then # Convert comma-separated conflicts back to newlines for display CONFLICTS_LIST=$(echo "${conflicts}" | tr ',' '\n' | sed 's/^/- /')