From d17fa582a897b3d28dd91021987a577fe182fe20 Mon Sep 17 00:00:00 2001 From: XargonWan Date: Tue, 5 Nov 2024 23:10:07 +0900 Subject: [PATCH] PR: deleting branch if already existing --- .github/workflows/pr_from_upstream.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/pr_from_upstream.yml b/.github/workflows/pr_from_upstream.yml index c6b9bea..2e1cafb 100644 --- a/.github/workflows/pr_from_upstream.yml +++ b/.github/workflows/pr_from_upstream.yml @@ -48,6 +48,19 @@ jobs: BRANCH_NAME: "sync-${{ github.run_id }}" # Temporary branch name for the PR run: | echo "Syncing from upstream repository ${{ env.UPSTREAM_REPO }} on branch ${{ env.TARGET_BRANCH }}" + + # Fetch and delete the branch if it exists locally + git fetch origin + if git rev-parse --verify "$BRANCH_NAME" >/dev/null 2>&1; then + echo "Branch $BRANCH_NAME exists locally. Deleting it." + git branch -D "$BRANCH_NAME" + fi + + # Check if the branch exists on the remote and delete it if it does + if git ls-remote --heads origin "$BRANCH_NAME" | grep "$BRANCH_NAME"; then + echo "Branch $BRANCH_NAME exists on the remote. Deleting it." + git push origin --delete "$BRANCH_NAME" + fi # Perform fetch and merge, attempting to resolve conflicts by preferring the upstream changes git fetch "${{ env.UPSTREAM_REPO }}" "${{ env.TARGET_BRANCH }}"