Skip to content

Commit af92988

Browse files
Add regression for duplicate-patch rebase stop
Co-authored-by: Andrew <andrewxhill@gmail.com>
1 parent 79b7e0b commit af92988

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

internal/git/rebase_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package git
2+
3+
import (
4+
"errors"
5+
"path/filepath"
6+
"strings"
7+
"testing"
8+
)
9+
10+
func TestRebaseCurrentBranchStopsWhenPatchAlreadyExistsUpstream(t *testing.T) {
11+
repoRoot := t.TempDir()
12+
runGitCommand(t, repoRoot, "git", "init", "-b", "main")
13+
runGitCommand(t, repoRoot, "git", "config", "user.name", "Test User")
14+
runGitCommand(t, repoRoot, "git", "config", "user.email", "test@example.com")
15+
runGitCommand(t, repoRoot, "git", "config", "commit.gpgsign", "false")
16+
runGitCommand(t, repoRoot, "git", "config", "tag.gpgsign", "false")
17+
runGitCommand(t, repoRoot, "git", "config", "core.hooksPath", ".git/hooks")
18+
19+
writeFile(t, filepath.Join(repoRoot, "README.md"), "# test\n")
20+
runGitCommand(t, repoRoot, "git", "add", "README.md")
21+
runGitCommand(t, repoRoot, "git", "commit", "-m", "initial")
22+
23+
runGitCommand(t, repoRoot, "git", "checkout", "-b", "feature/duplicate-patch")
24+
writeFile(t, filepath.Join(repoRoot, "README.md"), "# test\nqueued change\n")
25+
runGitCommand(t, repoRoot, "git", "commit", "-am", "feature patch")
26+
27+
runGitCommand(t, repoRoot, "git", "checkout", "main")
28+
writeFile(t, filepath.Join(repoRoot, "README.md"), "# test\nqueued change\n")
29+
runGitCommand(t, repoRoot, "git", "commit", "-am", "upstream patch")
30+
31+
runGitCommand(t, repoRoot, "git", "checkout", "feature/duplicate-patch")
32+
err := NewEngine(repoRoot).RebaseCurrentBranch(repoRoot, "main")
33+
if !errors.Is(err, ErrRebaseEmpty) {
34+
t.Fatalf("expected ErrRebaseEmpty for duplicate patch rebase, got %v", err)
35+
}
36+
37+
status := runGitCommand(t, repoRoot, "git", "status")
38+
if !strings.Contains(status, "rebase in progress") {
39+
t.Fatalf("expected repository to remain in rebase state, got %q", status)
40+
}
41+
}

0 commit comments

Comments
 (0)