From 10d5ebf231bdc37293235a6fc2bdf94fd25d0c56 Mon Sep 17 00:00:00 2001 From: Sami Hiltunen Date: Fri, 23 Oct 2020 14:17:38 +0200 Subject: 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. --- diff.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'diff.go') 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 -- cgit v1.2.3