Skip to content

Commit 9681264

Browse files
committed
Fix the squash-commit idempotency check to resolve in real action runs
has_squash_commit compared the target with a bare branch name like "main". actions/checkout leaves a detached HEAD and creates no local branches, so "main" does not resolve and git exits 128, which the if silently reads as "not up-to-date". The skip branch was therefore dead in CI and only worked in tests, where the test repos have every branch locally. This matters on the resume path: the push that finishes conflict resolution fires a synchronize event while the conflict label is still on. If that second run loses the race against the label removal, the broken check let it re-run the whole merge and push a second redundant synthetic merge commit. Compare against origin/$TARGET_BRANCH instead. With fetch-depth: 0 the remote-tracking ref always exists, so the check works in production while staying correct in tests.
1 parent 2d2469a commit 9681264

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

update-pr-stack.sh

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ check_env_var() {
6464

6565
# Check if a branch already has the squash commit merged (squash-merge mode only)
6666
# Requires SQUASH_COMMIT ref to be set via git update-ref
67-
#
68-
# Note: This uses local branch refs. The caller must ensure both branches
69-
# exist locally before calling (e.g., via git checkout).
7067
has_squash_commit() {
7168
local BRANCH="$1"
7269
local BASE="$2"
@@ -78,12 +75,11 @@ update_direct_target() {
7875
local BRANCH="$1"
7976
local BASE_BRANCH="$2"
8077

81-
# Checkout first to ensure the local branch exists (created from origin if
82-
# needed). This allows has_squash_commit to compare local refs, which matters
83-
# for testing where the script may run multiple times in the same repo.
8478
log_cmd git checkout "$BRANCH"
8579

86-
if has_squash_commit "$BRANCH" "$TARGET_BRANCH"; then
80+
# The target branch is never checked out, so it has no local ref, only the
81+
# remote-tracking one; a bare $TARGET_BRANCH would not resolve.
82+
if has_squash_commit "$BRANCH" "origin/$TARGET_BRANCH"; then
8783
echo "$BRANCH already up-to-date; skipping"
8884
return 0
8985
fi

0 commit comments

Comments
 (0)