Skip to content

feat(vcs): auto-rebase and retry a push when the remote moved ahead - #62

Merged
enisze merged 1 commit into
mainfrom
feature/auto-rebase-on-push
Aug 19, 2026
Merged

feat(vcs): auto-rebase and retry a push when the remote moved ahead#62
enisze merged 1 commit into
mainfrom
feature/auto-rebase-on-push

Conversation

@enisze

@enisze enisze commented Aug 19, 2026

Copy link
Copy Markdown
Owner

Problem

When pushing, if the remote branch had commits the local branch didn't, GitVcsDriver.pushCurrentBranch failed hard with "The remote branch has commits this branch doesn't. Pull or rebase onto the remote branch, then push again." — leaving the user to fetch, rebase, and push by hand every time.

Fix

The push now self-heals the common non-fast-forward case. When a push is rejected only because the remote moved ahead, the driver:

  1. Fetches the exact remote branch it's pushing to (git fetch <remote> <branch>).
  2. Rebases the local commits onto it (git rebase FETCH_HEAD).
  3. Retries the push once.

Safety:

  • A rebase that hits conflicts is aborted (git rebase --abort) so the working tree is never left mid-rebase, and the conflict is surfaced with an actionable message.
  • Only non-fast-forward rejections are retried — auth failures, missing workflow scope, and branch-protection rejections still fail fast, unchanged.
  • The retry is single-shot (no further auto-rebase), so a second rejection fails normally.

Applies to all remote-targeted push paths: existing upstream, new upstream (-u), and explicit remoteName.

Tests

Added two integration tests in GitVcsDriverCore.test.ts (real git, real temp remotes):

  • auto-rebases onto the remote and retries when the remote moved ahead (both commits end up on the remote, history linear).
  • aborts the auto-rebase and leaves a clean tree when it conflicts (not mid-rebase, local commit intact, actionable error).

All 56 tests in the file pass.

🤖 Generated with Claude Code

pushCurrentBranch failed hard on a non-fast-forward rejection, leaving
the user to fetch/rebase/push by hand. Now, when a push is rejected only
because the remote branch has commits the local branch doesn't, the
driver fetches that remote branch, rebases the local commits onto it,
and retries the push once. A rebase that hits conflicts is aborted so the
working tree is never left mid-rebase, and the conflict is surfaced with
actionable detail. Auth/branch-protection failures still fail fast.

Applies to all remote-targeted push paths (existing upstream, new
upstream, and explicit remote).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@enisze
enisze merged commit f066ab1 into main Aug 19, 2026
@enisze
enisze deleted the feature/auto-rebase-on-push branch August 19, 2026 07:41
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.

1 participant