Skip to content

Fix for replaying amended parent commits during rebase - #333

Open
skarim wants to merge 1 commit into
skarim/trunk-rebase-fixfrom
skarim/rebase-onto-amended-commits
Open

Fix for replaying amended parent commits during rebase#333
skarim wants to merge 1 commit into
skarim/trunk-rebase-fixfrom
skarim/rebase-onto-amended-commits

Conversation

@skarim

@skarim skarim commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Amending a lower branch and then running gh stack push could overwrite its
child's recorded base with a commit the child did not contain. The next
rebase would replay the old parent commit into the child, creating duplicate
history or unnecessary conflicts.

This preserves the last valid recorded base and only uses validated ancestor
commits as rebase --onto boundaries. Existing corrupted metadata can be
recovered from the parent reflog; when no safe boundary is available, the
command stops instead of guessing and rewriting history incorrectly.

Testing

  • go vet ./...
  • go test -race -count=1 ./...
  • Real-Git coverage for amend → push → rebase
  • Coverage for corrupted metadata recovery and safe no-reflog failure

Stack created with GitHub Stacks CLIGive Feedback 💬

Preserve a branch's last valid base when its parent is rewritten, and only
use verified ancestor commits as rebase boundaries. Recover previously
corrupted metadata from the parent reflog when possible, otherwise stop
safely instead of replaying superseded parent commits.
@skarim
skarim force-pushed the skarim/rebase-onto-amended-commits branch from 346396d to 6dca4c9 Compare July 28, 2026 06:26
@skarim
skarim marked this pull request as ready for review July 28, 2026 06:30
Copilot AI review requested due to automatic review settings July 28, 2026 06:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Prevents amended parent commits from being replayed during stacked rebases by preserving safe base metadata and recovering boundaries from reflogs.

Changes:

  • Validates recorded rebase boundaries before updating or using them.
  • Adds git merge-base --fork-point support.
  • Adds unit and real-Git regression coverage for issue #250.
Show a summary per file
File Description
internal/git/mock_ops.go Adds fork-point mocking support.
internal/git/gitops.go Implements the fork-point Git operation.
internal/git/git.go Exposes the fork-point wrapper.
cmd/utils.go Preserves and resolves safe rebase boundaries.
cmd/utils_test.go Tests base preservation.
cmd/sync_test.go Updates sync fork-point coverage.
cmd/rebase_test.go Adds rebase unit and integration regressions.

Review details

  • Files reviewed: 7/7 changed files
  • Comments generated: 0
  • Review effort level: Medium

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.

2 participants