This commit is contained in:
Ian Gulliver
2026-10-14 21:01:38 -07:00
parent 9e741ede32
commit b2bd894677
20 changed files with 585 additions and 343 deletions
+2 -71
View File
@@ -259,80 +259,11 @@ func TestMergeTask(t *testing.T) {
if code != http.StatusBadRequest {
t.Fatalf("want 400 merging without a git identity, got %d", code)
}
h.do("PUT", "/api/me", api.UserUpdate{GitName: "Alice", GitEmail: "alice@example.org"}, nil)
writeFile(t, filepath.Join(task.WorktreePath, "committed"), "one\ntwo\n")
gitOut(t, task.WorktreePath, "add", "committed")
gitOut(t, task.WorktreePath, "commit", "--message", "wip")
writeFile(t, filepath.Join(task.WorktreePath, "uncommitted"), "three\n")
writeFile(t, filepath.Join(p.RepoPath, "other"), "main moved\n")
gitOut(t, p.RepoPath, "add", "other")
gitOut(t, p.RepoPath, "commit", "--message", "main moved")
moved := gitOut(t, p.RepoPath, "rev-parse", "main")
unmerged := api.Unmerged{}
h.do("GET", "/api/tasks/"+task.Id+"/unmerged", nil, &unmerged)
if unmerged != (api.Unmerged{Commits: 1, Files: 2, Insertions: 3, Deletions: 0, Uncommitted: 1}) {
t.Fatalf("unexpected unmerged %+v", unmerged)
}
merged := api.Task{}
code = h.do("POST", "/api/tasks/"+task.Id+"/merge", nil, &merged)
if code != http.StatusOK || merged.Status != api.TaskStatusMerged || merged.ClosedAt == nil || merged.MergeCommit == nil {
t.Fatalf("merge: %d %+v", code, merged)
}
head := gitOut(t, p.RepoPath, "rev-parse", "main")
if head != *merged.MergeCommit {
t.Fatalf("main at %s, want merge commit %s", head, *merged.MergeCommit)
}
if parent := gitOut(t, p.RepoPath, "rev-parse", "main^"); parent != moved {
t.Fatalf("merge commit parent %s, want %s", parent, moved)
}
if log := gitOut(t, p.RepoPath, "log", "-1", "--format=%s|%an|%cn"); log != "Add notes|Alice|Alice" {
t.Fatalf("unexpected merge commit %s", log)
}
for _, name := range []string{"committed", "uncommitted", "other"} {
_, err := os.Stat(filepath.Join(p.RepoPath, name))
if err != nil {
t.Fatalf("%s not checked out on main: %v", name, err)
}
}
if status := gitOut(t, p.RepoPath, "status", "--porcelain"); status != "" {
t.Fatalf("main checkout dirty after merge: %s", status)
}
if branches := gitOut(t, p.RepoPath, "branch", "--list", task.Branch); branches != "" {
t.Fatalf("branch still exists: %s", branches)
}
}
func TestMergeConflict(t *testing.T) {
h := newHarness(t)
p := h.createProject("demo")
h.do("PUT", "/api/me", api.UserUpdate{GitName: "Alice", GitEmail: "alice@example.org"}, nil)
task := api.Task{}
h.do("POST", "/api/projects/"+p.Id+"/tasks", api.TaskCreate{Title: "Edit readme"}, &task)
writeFile(t, filepath.Join(task.WorktreePath, "README"), "task\n")
writeFile(t, filepath.Join(p.RepoPath, "README"), "main\n")
gitOut(t, p.RepoPath, "commit", "--all", "--message", "main edit")
head := gitOut(t, p.RepoPath, "rev-parse", "main")
code := h.do("POST", "/api/tasks/"+task.Id+"/merge", nil, nil)
if code != http.StatusConflict {
t.Fatalf("want 409 on conflict, got %d", code)
}
got := api.Task{}
h.do("GET", "/api/tasks/"+task.Id, nil, &got)
if got.Status != api.TaskStatusActive || gitOut(t, p.RepoPath, "rev-parse", "main") != head {
t.Fatalf("conflicted merge changed state: %+v", got)
}
_, err := os.Stat(task.WorktreePath)
if err != nil {
t.Fatalf("worktree removed after conflict: %v", err)
if got.Status != api.TaskStatusActive {
t.Fatalf("refused merge changed the task: %+v", got)
}
}