|
| 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