MCPcopy Create free account
hub / github.com/libgit2/git2go / TestRebaseInMemoryWithConflict

Function TestRebaseInMemoryWithConflict

rebase_test.go:17–89  ·  view source on GitHub ↗

Tests

(t *testing.T)

Source from the content-addressed store, hash-verified

15// Tests
16
17func TestRebaseInMemoryWithConflict(t *testing.T) {
18 repo := createTestRepo(t)
19 defer cleanupTestRepo(t, repo)
20 seedTestRepo(t, repo)
21
22 // Create two branches with common history, where both modify "common-file"
23 // in a conflicting way.
24 _, err := commitSomething(repo, "common-file", "a\nb\nc\n", commitOptions{})
25 checkFatal(t, err)
26 checkFatal(t, createBranch(repo, "branch-a"))
27 checkFatal(t, createBranch(repo, "branch-b"))
28
29 checkFatal(t, repo.SetHead("refs/heads/branch-a"))
30 _, err = commitSomething(repo, "common-file", "1\nb\nc\n", commitOptions{})
31 checkFatal(t, err)
32
33 checkFatal(t, repo.SetHead("refs/heads/branch-b"))
34 _, err = commitSomething(repo, "common-file", "x\nb\nc\n", commitOptions{})
35 checkFatal(t, err)
36
37 branchA, err := repo.LookupBranch("branch-a", BranchLocal)
38 checkFatal(t, err)
39 onto, err := repo.AnnotatedCommitFromRef(branchA.Reference)
40 checkFatal(t, err)
41
42 // We then rebase "branch-b" onto "branch-a" in-memory, which should result
43 // in a conflict.
44 rebase, err := repo.InitRebase(nil, nil, onto, &RebaseOptions{InMemory: 1})
45 checkFatal(t, err)
46
47 _, err = rebase.Next()
48 checkFatal(t, err)
49
50 index, err := rebase.InmemoryIndex()
51 checkFatal(t, err)
52
53 // We simply resolve the conflict and commit the rebase.
54 if !index.HasConflicts() {
55 t.Fatal("expected index to have conflicts")
56 }
57
58 conflict, err := index.Conflict("common-file")
59 checkFatal(t, err)
60
61 resolvedBlobID, err := repo.CreateBlobFromBuffer([]byte("resolved contents"))
62 checkFatal(t, err)
63
64 resolvedEntry := *conflict.Our
65 resolvedEntry.Id = resolvedBlobID
66 checkFatal(t, index.Add(&resolvedEntry))
67 checkFatal(t, index.RemoveConflict("common-file"))
68
69 var commitID Oid
70 checkFatal(t, rebase.Commit(&commitID, signature(), signature(), "rebased message"))
71 checkFatal(t, rebase.Finish())
72
73 // And then assert that we can look up the new merge commit, and that the
74 // "common-file" has the expected contents.

Callers

nothing calls this directly

Calls 15

createTestRepoFunction · 0.85
cleanupTestRepoFunction · 0.85
seedTestRepoFunction · 0.85
commitSomethingFunction · 0.85
checkFatalFunction · 0.85
createBranchFunction · 0.85
signatureFunction · 0.85
SetHeadMethod · 0.80
LookupBranchMethod · 0.80
InitRebaseMethod · 0.80
InmemoryIndexMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…