summaryrefslogtreecommitdiff
path: root/diff.go
diff options
context:
space:
mode:
authorSami Hiltunen <[email protected]>2020-10-23 14:17:38 +0200
committerGitHub <[email protected]>2020-10-23 05:17:38 -0700
commit10d5ebf231bdc37293235a6fc2bdf94fd25d0c56 (patch)
treee09005e2e5f5c2a31e490dbd6104a8d4993113dc /diff.go
parent3a4204bd934b59a55581d33d300617a4f621257f (diff)
apply: Add bindings for git_apply_to_tree (#657)
Adds bindings to the git_apply_to_tree function that allows applying a diff directly to a tree.
Diffstat (limited to 'diff.go')
-rw-r--r--diff.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/diff.go b/diff.go
index f65a2dd..76838e7 100644
--- a/diff.go
+++ b/diff.go
@@ -991,6 +991,24 @@ func (v *Repository) ApplyDiff(diff *Diff, location ApplyLocation, opts *ApplyOp
return nil
}
+// ApplyToTree applies a Diff to a Tree and returns the resulting image as an Index.
+func (v *Repository) ApplyToTree(diff *Diff, tree *Tree, opts *ApplyOptions) (*Index, error) {
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ var indexPtr *C.git_index
+ cOpts := opts.toC()
+ ecode := C.git_apply_to_tree(&indexPtr, v.ptr, tree.cast_ptr, diff.ptr, cOpts)
+ runtime.KeepAlive(diff)
+ runtime.KeepAlive(tree)
+ runtime.KeepAlive(cOpts)
+ if ecode != 0 {
+ return nil, MakeGitError(ecode)
+ }
+
+ return newIndexFromC(indexPtr, v), nil
+}
+
// DiffFromBuffer reads the contents of a git patch file into a Diff object.
//
// The diff object produced is similar to the one that would be produced if you