Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func rebaseContinueOnce(opts RebaseOpts) error {
func tryAutoResolveRebase(originalErr error, opts RebaseOpts) error {
for i := 0; i < 1000; i++ {
if !IsRebaseInProgress() {
return nil
return originalErr

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Treat non-started rebase errors as fatal

When git rebase fails before creating .git/rebase-* (for example an invalid or missing branch/old-base ref), this now returns a non-nil error while IsRebaseInProgress() is false. The stack callers such as cascadeRebase treat any non-nil Rebase/RebaseOnto error as a recoverable conflict, save gh-stack-rebase-state, and tell users to run gh stack rebase --continue, but there is no Git rebase to continue, so the original failure is still not surfaced correctly and the user is left in a bogus recovery state. Please return a distinguishable fatal error here or update callers to branch on whether a rebase actually started.

Useful? React with 👍 / 👎.

}
conflicts, err := ConflictedFiles()
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions internal/git/gitops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ func setupBareAndClone(t *testing.T) (string, string) {
return bareDir, cloneDir
}

func TestRebaseOntoReportsFailureBeforeRebaseStarts(t *testing.T) {
_, cloneDir := setupBareAndClone(t)
restore := withGitDir(t, cloneDir)
defer restore()

err := (&defaultOps{}).RebaseOnto("main", "main", "missing", RebaseOpts{})
require.Error(t, err)
assert.False(t, (&defaultOps{}).IsRebaseInProgress())
}

// writeFile creates or overwrites a file in dir.
func writeFile(t *testing.T, dir, name, content string) {
t.Helper()
Expand Down