2121# branch is deleted and GitHub auto-retargets to main.
2222#
2323# Setup:
24- # - Enable "auto-delete head branches" in repo settings
2524# - Create 2-PR stack: main <- noact_feature1 <- noact_feature2
2625# - Each PR modifies a different line (3 and 4)
2726#
2827# Test:
2928# - Capture noact_feature2's initial diff (shows only its own 1-line change)
30- # - Merge noact_feature1 (GitHub auto-deletes branch and retargets PR2 to main)
29+ # - Merge noact_feature1, then delete the branch
30+ # - GitHub auto-retargets PR2 to main
3131# - Verify noact_feature2's diff is NOW POLLUTED (shows accumulated changes)
3232#
3333# Then installs the action for subsequent scenarios.
@@ -515,8 +515,8 @@ log_cmd git push -u origin main
515515# This scenario proves that without the action, PR diffs become polluted
516516# when the base branch is deleted and GitHub auto-retargets to main.
517517#
518- # We enable "auto-delete head branches" so GitHub automatically :
519- # 1. Deletes the merged branch
518+ # After merging the base PR, we delete the branch. GitHub then :
519+ # 1. Detects the deleted branch
520520# 2. Retargets child PRs to the default branch (main)
521521#
522522# This causes the child PR's diff to show accumulated changes instead of
@@ -525,13 +525,9 @@ log_cmd git push -u origin main
525525
526526echo >&2 " --- SCENARIO 0: Diff Pollution Test (without action) ---"
527527
528- # Enable auto-delete head branches to trigger GitHub's auto-retarget behavior
529- echo >&2 " 0a. Enabling auto-delete head branches..."
530- log_cmd gh api -X PATCH " /repos/$REPO_FULL_NAME " --input - <<< ' {"delete_branch_on_merge":true}'
531-
532528# Create 2 PRs for the no-action test (using prefix 'noact_')
533529# Each feature changes a DIFFERENT line so pollution is clearly visible
534- echo >&2 " 0b . Creating 'no action' stack..."
530+ echo >&2 " 0a . Creating 'no action' stack..."
535531log_cmd git checkout main
536532log_cmd git checkout -b noact_feature1 main
537533sed -i ' 3s/.*/NoAct Feature 1 line 3/' file.txt # Feature 1 changes LINE 3
@@ -552,37 +548,23 @@ NOACT_PR2_NUM=$(echo "$NOACT_PR2_URL" | awk -F'/' '{print $NF}')
552548echo >&2 " Created NoAct PR #$NOACT_PR2_NUM : $NOACT_PR2_URL "
553549
554550# Capture initial diff (should show only 1 line change)
555- echo >&2 " 0c . Capturing initial diff for PR2..."
551+ echo >&2 " 0b . Capturing initial diff for PR2..."
556552NOACT_PR2_DIFF_INITIAL=$( get_pr_diff " $NOACT_PR2_URL " )
557553echo >&2 " --- Initial PR2 diff (vs noact_feature1) ---"
558554echo " $NOACT_PR2_DIFF_INITIAL " >&2
559555echo >&2 " ----------------------------------------------"
560556
561557# Merge bottom PR WITHOUT the action installed
562- # With auto- delete enabled, GitHub will delete noact_feature1 and retarget PR2 to main
563- echo >&2 " 0d . Merging NoAct PR1 (without action installed)..."
558+ # Then delete the branch to trigger GitHub's auto- retarget of PR2 to main
559+ echo >&2 " 0c . Merging NoAct PR1 (without action installed)..."
564560merge_pr_with_retry " $NOACT_PR1_URL "
565- echo >&2 " NoAct PR1 merged. Branch should be auto-deleted and PR2 auto-retargeted."
566-
567- # Wait for GitHub to delete the branch (async operation)
568- echo >&2 " Waiting for noact_feature1 branch to be deleted..."
569- branch_deleted=false
570- for attempt in {1..10}; do
571- if ! gh api " /repos/$REPO_FULL_NAME /branches/noact_feature1" & > /dev/null; then
572- echo >&2 " ✅ Branch noact_feature1 was deleted (attempt $attempt )."
573- branch_deleted=true
574- break
575- fi
576- echo >&2 " Attempt $attempt /10: Branch still exists, waiting..."
577- sleep 2
578- done
579-
580- if [[ " $branch_deleted " != " true" ]]; then
581- echo >&2 " ❌ Branch noact_feature1 still exists after 10 attempts!"
582- echo >&2 " Repo settings:"
583- gh api " /repos/$REPO_FULL_NAME " --jq ' {delete_branch_on_merge}' >&2
584- exit 1
585- fi
561+ echo >&2 " NoAct PR1 merged."
562+
563+ # Delete the branch to trigger auto-retarget
564+ # Note: repo setting 'delete_branch_on_merge' only works for web UI merges, not gh CLI
565+ echo >&2 " Deleting noact_feature1 branch to trigger auto-retarget..."
566+ log_cmd gh api -X DELETE " /repos/$REPO_FULL_NAME /git/refs/heads/noact_feature1"
567+ echo >&2 " Branch deleted. Waiting for GitHub to auto-retarget PR2 to main..."
586568
587569# Wait for GitHub to auto-retarget PR2 to main
588570if ! wait_for_pr_base_change " $NOACT_PR2_NUM " " main" ; then
608590
609591echo >&2 " --- SCENARIO 0 PASSED: Diff pollution demonstrated ---"
610592
611- # Disable auto-delete for remaining scenarios (action handles branch deletion)
612- echo >&2 " Disabling auto-delete head branches for remaining scenarios..."
613- log_cmd gh api -X PATCH " /repos/$REPO_FULL_NAME " --input - <<< ' {"delete_branch_on_merge":false}'
614-
615593# Install the action workflow for subsequent scenarios
616- echo >&2 " 0e . Installing action and workflow..."
594+ echo >&2 " 0d . Installing action and workflow..."
617595log_cmd git checkout main
618596log_cmd git pull origin main
619597
0 commit comments