e2e/mergerecord_test.go

d775997ead04022093817ab513287b5886065247
gitbay/e2e/mergerecord_test.go history · blame · raw

49 lines · 2162 bytes

 1package e2e
 2
 3import (
 4	"os"
 5	"path/filepath"
 6	"strings"
 7	"testing"
 8)
 9
10// A merge request whose head the target already contains is recorded as
11// merged rather than refused: the branch was merged by hand and pushed,
12// or a merge moved the ref and then failed to record itself. Either way
13// refusing left the merge request open for good (#108).
14func TestMergeRecordedWhenTargetContainsHead(t *testing.T) {
15	inst := startInstance(t)
16	aliceKey := inst.newKey(t, "alice")
17	inst.admin(t, "admin", "user", "create", "alice", "--key", aliceKey+".pub")
18	if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/app"); code != 0 {
19		t.Fatalf("repo create: %s", errOut)
20	}
21	work := t.TempDir()
22	env := inst.gitEnv(aliceKey)
23	mustGit(t, work, env, "clone", inst.sshURL("alice/app"), "w")
24	dir := filepath.Join(work, "w")
25	os.WriteFile(filepath.Join(dir, "f.txt"), []byte("x\n"), 0o644)
26	mustGit(t, dir, env, "checkout", "-q", "-b", "main")
27	mustGit(t, dir, env, "add", ".")
28	mustGit(t, dir, env, "commit", "-q", "-m", "base")
29	mustGit(t, dir, env, "push", "-q", "origin", "main")
30	mustGit(t, dir, env, "checkout", "-q", "-b", "feat")
31	os.WriteFile(filepath.Join(dir, "f.txt"), []byte("y\n"), 0o644)
32	mustGit(t, dir, env, "add", ".")
33	mustGit(t, dir, env, "commit", "-q", "-m", "change")
34	mustGit(t, dir, env, "push", "-q", "origin", "feat")
35	if _, errOut, code := inst.ssh(t, aliceKey, "", "mr", "create", "alice/app", "--source", "feat", "--target", "main", "--title", "change"); code != 0 {
36		t.Fatalf("mr create: %s", errOut)
37	}
38	// Merged by hand: main fast-forwards to the branch outside the forge.
39	mustGit(t, dir, env, "push", "-q", "origin", "feat:main")
40
41	out, errOut, code := inst.ssh(t, aliceKey, "", "mr", "merge", "alice/app", "1", "--json")
42	if code != 0 || !strings.Contains(out, `"strategy":"recorded"`) {
43		t.Fatalf("merge of an already-landed head: exit %d\n%s%s", code, out, errOut)
44	}
45	show, _, _ := inst.ssh(t, aliceKey, "", "mr", "show", "alice/app", "1", "--json")
46	if !strings.Contains(show, `"state":"merged"`) || !strings.Contains(show, `"merged_by":"alice"`) {
47		t.Fatalf("merge request not recorded as merged:\n%s", show)
48	}
49}