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
9
merge.go
9
merge.go
|
@ -206,8 +206,11 @@ func (r *Repository) MergeTrees(ancestor *Tree, ours *Tree, theirs *Tree, option
|
||||||
copts := options.toC()
|
copts := options.toC()
|
||||||
|
|
||||||
idx := &Index{}
|
idx := &Index{}
|
||||||
|
var ancestor_ptr *C.git_tree
|
||||||
ret := C.git_merge_trees(&idx.ptr, r.ptr, ancestor.cast_ptr, ours.cast_ptr, theirs.cast_ptr, copts)
|
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 {
|
if ret < 0 {
|
||||||
return nil, MakeGitError(ret)
|
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
|
// 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) {
|
func populateCMergeFileInput(c *C.git_merge_file_input, input MergeFileInput) {
|
||||||
c.path = C.CString(input.Path)
|
c.path = C.CString(input.Path)
|
||||||
|
if input.Contents != nil {
|
||||||
c.ptr = (*C.char)(unsafe.Pointer(&input.Contents[0]))
|
c.ptr = (*C.char)(unsafe.Pointer(&input.Contents[0]))
|
||||||
c.size = C.size_t(len(input.Contents))
|
c.size = C.size_t(len(input.Contents))
|
||||||
|
}
|
||||||
c.mode = C.uint(input.Mode)
|
c.mode = C.uint(input.Mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package git
|
package git
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -64,6 +65,28 @@ func TestMergeSameFile(t *testing.T) {
|
||||||
|
|
||||||
compareBytes(t, file.Contents, result.Contents)
|
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) {
|
func compareBytes(t *testing.T, expected, actual []byte) {
|
||||||
|
|
Loading…
Reference in New Issue