Skip to content

Fast-forward autoloop/* branches when ahead=0 instead of merging#43

Merged
mrjf merged 3 commits intomainfrom
copilot/update-fast-forward-branch-strategy
Apr 23, 2026
Merged

Fast-forward autoloop/* branches when ahead=0 instead of merging#43
mrjf merged 3 commits intomainfrom
copilot/update-fast-forward-branch-strategy

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 22, 2026

The unconditional git merge origin/main in Step 3 (and in the companion sync-branches workflow) produced noisy "Merge main into branch" commits whenever a long-running branch had no unique commits. Those merge commits re-exposed every historical file as a patch touch, aggregating to >100 file changes on the next iteration's PR and tripping gh-aw's hard-coded E003 limit.

Changes

  • workflows/autoloop.md — Replaced the Step 3 prose (and its content-delta git diff heuristic + bare git reset --hard) with an explicit four-case decision tree keyed on git rev-list --count ahead/behind:

    ahead behind Action
    0 0 checkout, no-op
    0 >0 fast-forward + push --force-with-lease
    >0 0 checkout, no-op
    >0 >0 checkout + merge
  • workflows/sync-branches.md (Node.js template) and .github/workflows/sync-branches.md (deployed Python copy) — Same four-case logic in the per-branch sync loop, so the companion workflow cannot re-introduce the noisy merge commits the per-iteration step now avoids.

  • .github/workflows/sync-branches.lock.yml — Regenerated via gh aw compile, with the two pre-existing manual fixups re-applied (permissions: contents: write; merge step ordered after Configure Git credentials).

--force-with-lease (not --force) so a concurrent push to the branch is rejected rather than clobbered. The fast-forward is lossless because ahead=0 proves every commit on the branch is already reachable from main.

ahead=$(git rev-list --count origin/main..origin/autoloop/{program-name})
behind=$(git rev-list --count origin/autoloop/{program-name}..origin/main)

if [ "$ahead" = "0" ] && [ "$behind" != "0" ]; then
  git checkout -B autoloop/{program-name} origin/main
  git push --force-with-lease origin autoloop/{program-name}
elif [ "$ahead" != "0" ] && [ "$behind" != "0" ]; then
  git checkout -B autoloop/{program-name} origin/autoloop/{program-name}
  git merge origin/main --no-edit -m "Merge main into autoloop/{program-name}"
else
  git checkout -B autoloop/{program-name} origin/autoloop/{program-name}
fi

Copilot AI changed the title [WIP] Update branch handling to fast-forward when ahead=0 Fast-forward autoloop/* branches when ahead=0 instead of merging Apr 22, 2026
Copilot finished work on behalf of mrjf April 22, 2026 22:33
Copilot AI requested a review from mrjf April 22, 2026 22:33
@mrjf mrjf marked this pull request as ready for review April 23, 2026 01:22
@mrjf
Copy link
Copy Markdown
Contributor

mrjf commented Apr 23, 2026

@copilot fix tests

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 23, 2026

@copilot fix tests

Fixed in a7c81f5. The CI failure was ModuleNotFoundError: No module named 'yaml' in test_lock_creds_before_merge.github/workflows/tests.yml only installs pytest, not pyyaml. Replaced the yaml.safe_load call with stdlib regex parsing (scoped to the agent: job body) so the test has no extra dependencies. All 100 tests pass locally.

Copilot finished work on behalf of mrjf April 23, 2026 01:27
@mrjf mrjf merged commit 716a4eb into main Apr 23, 2026
1 check passed
@mrjf mrjf deleted the copilot/update-fast-forward-branch-strategy branch April 23, 2026 02:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fast-forward the long-running branch to main when ahead=0, instead of always merging

2 participants