Skip to content

Commit 4b8fab3

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 4b8fab3

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

update-pr-stack.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,11 @@ check_env_var() {
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
6767
#
68-
# Note: This uses local branch refs. The caller must ensure both branches
69-
# exist locally before calling (e.g., via git checkout).
68+
# BASE must be a ref that resolves in a real action run: actions/checkout leaves
69+
# a detached HEAD with no local branches, so a bare name like "main" does not
70+
# exist and git fails with exit 128 (silently read as "not an ancestor"). Pass
71+
# the remote-tracking ref (origin/$TARGET_BRANCH); fetch-depth: 0 guarantees it
72+
# is present. BRANCH is the locally checked-out head being updated.
7073
has_squash_commit() {
7174
local BRANCH="$1"
7275
local BASE="$2"
@@ -79,11 +82,11 @@ update_direct_target() {
7982
local BASE_BRANCH="$2"
8083

8184
# 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.
85+
# needed) so has_squash_commit and the merge below operate on it. The target
86+
# is compared via its remote-tracking ref, which always exists.
8487
log_cmd git checkout "$BRANCH"
8588

86-
if has_squash_commit "$BRANCH" "$TARGET_BRANCH"; then
89+
if has_squash_commit "$BRANCH" "origin/$TARGET_BRANCH"; then
8790
echo "$BRANCH already up-to-date; skipping"
8891
return 0
8992
fi

0 commit comments

Comments
 (0)