summaryrefslogtreecommitdiff
path: root/rebase_test.go
diff options
context:
space:
mode:
authorPatrick Steinhardt <[email protected]>2022-02-24 14:27:26 +0100
committerGitHub <[email protected]>2022-02-24 05:27:26 -0800
commite7d1b2b69fbe476c75a00cf8dcda284337facb50 (patch)
tree7d90ef52471591ae21a3a36b730f0e864487a304 /rebase_test.go
parentc598ea5718d76bd08475172367236e27f1ed7dbf (diff)
rebase: Add wrapper for `git_rebase_inmemory_index()` (#900)
* rebase: Fix missing initialization of the repo pointer While the `Rebase` structure has a pointer to the repository the rebase is creatde in, this pointer isn't ever initialized. Fix this. * rebase: Add wrapper for `git_rebase_inmemory_index()` Add a new wrapper for `git_rebase_inmemory_index()`, which can be used to retrieve the index for an in-memory rebase. Co-authored-by: Patrick Steinhardt <[email protected]>
Diffstat (limited to 'rebase_test.go')
-rw-r--r--rebase_test.go74
1 files changed, 74 insertions, 0 deletions
diff --git a/rebase_test.go b/rebase_test.go
index 65df522..779e1a5 100644
--- a/rebase_test.go
+++ b/rebase_test.go
@@ -14,6 +14,80 @@ import (
// Tests
+func TestRebaseInMemoryWithConflict(t *testing.T) {
+ repo := createTestRepo(t)
+ defer cleanupTestRepo(t, repo)
+ seedTestRepo(t, repo)
+
+ // Create two branches with common history, where both modify "common-file"
+ // in a conflicting way.
+ _, err := commitSomething(repo, "common-file", "a\nb\nc\n", commitOptions{})
+ checkFatal(t, err)
+ checkFatal(t, createBranch(repo, "branch-a"))
+ checkFatal(t, createBranch(repo, "branch-b"))
+
+ checkFatal(t, repo.SetHead("refs/heads/branch-a"))
+ _, err = commitSomething(repo, "common-file", "1\nb\nc\n", commitOptions{})
+ checkFatal(t, err)
+
+ checkFatal(t, repo.SetHead("refs/heads/branch-b"))
+ _, err = commitSomething(repo, "common-file", "x\nb\nc\n", commitOptions{})
+ checkFatal(t, err)
+
+ branchA, err := repo.LookupBranch("branch-a", BranchLocal)
+ checkFatal(t, err)
+ onto, err := repo.AnnotatedCommitFromRef(branchA.Reference)
+ checkFatal(t, err)
+
+ // We then rebase "branch-b" onto "branch-a" in-memory, which should result
+ // in a conflict.
+ rebase, err := repo.InitRebase(nil, nil, onto, &RebaseOptions{InMemory: 1})
+ checkFatal(t, err)
+
+ _, err = rebase.Next()
+ checkFatal(t, err)
+
+ index, err := rebase.InmemoryIndex()
+ checkFatal(t, err)
+
+ // We simply resolve the conflict and commit the rebase.
+ if !index.HasConflicts() {
+ t.Fatal("expected index to have conflicts")
+ }
+
+ conflict, err := index.Conflict("common-file")
+ checkFatal(t, err)
+
+ resolvedBlobID, err := repo.CreateBlobFromBuffer([]byte("resolved contents"))
+ checkFatal(t, err)
+
+ resolvedEntry := *conflict.Our
+ resolvedEntry.Id = resolvedBlobID
+ checkFatal(t, index.Add(&resolvedEntry))
+ checkFatal(t, index.RemoveConflict("common-file"))
+
+ var commitID Oid
+ checkFatal(t, rebase.Commit(&commitID, signature(), signature(), "rebased message"))
+ checkFatal(t, rebase.Finish())
+
+ // And then assert that we can look up the new merge commit, and that the
+ // "common-file" has the expected contents.
+ commit, err := repo.LookupCommit(&commitID)
+ checkFatal(t, err)
+ if commit.Message() != "rebased message" {
+ t.Fatalf("unexpected commit message %q", commit.Message())
+ }
+
+ tree, err := commit.Tree()
+ checkFatal(t, err)
+
+ blob, err := repo.LookupBlob(tree.EntryByName("common-file").Id)
+ checkFatal(t, err)
+ if string(blob.Contents()) != "resolved contents" {
+ t.Fatalf("unexpected resolved blob contents %q", string(blob.Contents()))
+ }
+}
+
func TestRebaseAbort(t *testing.T) {
// TEST DATA