MCPcopy Create free account
hub / github.com/libgit2/git2go / ApplyDiff

Method ApplyDiff

diff.go:1030–1050  ·  view source on GitHub ↗

ApplyDiff appllies a Diff to the given repository, making changes directly in the working directory, the index, or both.

(diff *Diff, location ApplyLocation, opts *ApplyOptions)

Source from the content-addressed store, hash-verified

1028// ApplyDiff appllies a Diff to the given repository, making changes directly
1029// in the working directory, the index, or both.
1030func (v *Repository) ApplyDiff(diff *Diff, location ApplyLocation, opts *ApplyOptions) error {
1031 runtime.LockOSThread()
1032 defer runtime.UnlockOSThread()
1033
1034 var err error
1035 cOpts := populateApplyOptions(&C.git_apply_options{}, opts, &err)
1036 defer freeApplyOptions(cOpts)
1037
1038 ret := C.git_apply(v.ptr, diff.ptr, C.git_apply_location_t(location), cOpts)
1039 runtime.KeepAlive(v)
1040 runtime.KeepAlive(diff)
1041 runtime.KeepAlive(cOpts)
1042 if ret == C.int(ErrorCodeUser) && err != nil {
1043 return err
1044 }
1045 if ret < 0 {
1046 return MakeGitError(ret)
1047 }
1048
1049 return nil
1050}
1051
1052// ApplyToTree applies a Diff to a Tree and returns the resulting image as an Index.
1053func (v *Repository) ApplyToTree(diff *Diff, tree *Tree, opts *ApplyOptions) (*Index, error) {

Callers 1

TestApplyDiffAddfileFunction · 0.80

Calls 3

populateApplyOptionsFunction · 0.85
freeApplyOptionsFunction · 0.85
MakeGitErrorFunction · 0.85

Tested by 1

TestApplyDiffAddfileFunction · 0.64