Merge pull request #134 from joseferminj/fix-merge-trees-nil-ancestor
Fix MergeTrees func to accept nil as ancestor parameter
This commit is contained in:
commit
61729f5c93
13
merge.go
13
merge.go
|
@ -206,8 +206,11 @@ func (r *Repository) MergeTrees(ancestor *Tree, ours *Tree, theirs *Tree, option
|
|||
copts := options.toC()
|
||||
|
||||
idx := &Index{}
|
||||
|
||||
ret := C.git_merge_trees(&idx.ptr, r.ptr, ancestor.cast_ptr, ours.cast_ptr, theirs.cast_ptr, copts)
|
||||
var ancestor_ptr *C.git_tree
|
||||
if ancestor != nil {
|
||||
ancestor_ptr = ancestor.cast_ptr
|
||||
}
|
||||
ret := C.git_merge_trees(&idx.ptr, r.ptr, ancestor_ptr, ours.cast_ptr, theirs.cast_ptr, copts)
|
||||
if ret < 0 {
|
||||
return nil, MakeGitError(ret)
|
||||
}
|
||||
|
@ -273,8 +276,10 @@ type MergeFileInput struct {
|
|||
// populate a C struct with merge file input, make sure to use freeMergeFileInput to clean up allocs
|
||||
func populateCMergeFileInput(c *C.git_merge_file_input, input MergeFileInput) {
|
||||
c.path = C.CString(input.Path)
|
||||
c.ptr = (*C.char)(unsafe.Pointer(&input.Contents[0]))
|
||||
c.size = C.size_t(len(input.Contents))
|
||||
if input.Contents != nil {
|
||||
c.ptr = (*C.char)(unsafe.Pointer(&input.Contents[0]))
|
||||
c.size = C.size_t(len(input.Contents))
|
||||
}
|
||||
c.mode = C.uint(input.Mode)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package git
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -64,6 +65,28 @@ func TestMergeSameFile(t *testing.T) {
|
|||
|
||||
compareBytes(t, file.Contents, result.Contents)
|
||||
|
||||
}
|
||||
func TestMergeTreesWithoutAncestor(t *testing.T) {
|
||||
repo := createTestRepo(t)
|
||||
defer repo.Free()
|
||||
defer os.RemoveAll(repo.Workdir())
|
||||
|
||||
_, originalTreeId := seedTestRepo(t, repo)
|
||||
originalTree, err := repo.LookupTree(originalTreeId)
|
||||
|
||||
checkFatal(t, err)
|
||||
|
||||
_, newTreeId := updateReadme(t, repo, "file changed\n")
|
||||
|
||||
newTree, err := repo.LookupTree(newTreeId)
|
||||
checkFatal(t, err)
|
||||
index, err := repo.MergeTrees(nil, originalTree, newTree, nil)
|
||||
if !index.HasConflicts() {
|
||||
t.Fatal("expected conflicts in the index")
|
||||
}
|
||||
_, err = index.GetConflict("README")
|
||||
checkFatal(t, err)
|
||||
|
||||
}
|
||||
|
||||
func compareBytes(t *testing.T, expected, actual []byte) {
|
||||
|
|
Loading…
Reference in New Issue