Skip to content

Commit c51d499

Browse files
committed
Refactor merge branch creation logic to reuse existing branches and ensure main is up to date
1 parent b38b5b7 commit c51d499

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

.github/scripts/merge-upstream-start.sh

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,23 @@ cd "$ROOT_DIR"
2020
UPSTREAM_REPO="https://github.com/github/copilot-sdk.git"
2121
ENV_FILE="$ROOT_DIR/.merge-env"
2222

23-
# ── 1. Create branch ──────────────────────────────────────────
24-
echo "▸ Ensuring we are on main and up to date…"
25-
git checkout main
26-
git pull origin main
23+
# ── 1. Create branch (or reuse existing) ─────────────────────
24+
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
2725

28-
BRANCH_NAME="merge-upstream-$(date +%Y%m%d)"
29-
echo "▸ Creating branch: $BRANCH_NAME"
30-
git checkout -b "$BRANCH_NAME"
26+
if [[ "$CURRENT_BRANCH" != "main" ]]; then
27+
# Already on a non-main branch (e.g., coding agent's auto-created PR branch).
28+
# Stay on this branch — do not create a new one.
29+
BRANCH_NAME="$CURRENT_BRANCH"
30+
echo "▸ Already on branch '$BRANCH_NAME' — reusing it (coding agent mode)."
31+
git pull origin main --no-edit 2>/dev/null || echo " (pull from main skipped or fast-forward not possible)"
32+
else
33+
echo "▸ Ensuring main is up to date…"
34+
git pull origin main
35+
36+
BRANCH_NAME="merge-upstream-$(date +%Y%m%d)"
37+
echo "▸ Creating branch: $BRANCH_NAME"
38+
git checkout -b "$BRANCH_NAME"
39+
fi
3140

3241
# ── 2. Update Copilot CLI ────────────────────────────────────
3342
echo "▸ Updating Copilot CLI…"

0 commit comments

Comments
 (0)