summaryrefslogtreecommitdiff
path: root/diff.go
diff options
context:
space:
mode:
authorHiroshi Ioka <[email protected]>2016-03-06 12:18:32 +0900
committerHiroshi Ioka <[email protected]>2016-03-11 02:25:33 +0900
commit975228d55c7c4875374bf79e022afb8fa725d660 (patch)
treed5c0224284ab3bb2065558fb8fde8a5bcf9ac6b7 /diff.go
parentd3bd8903f8310baf5395d63aec1e3d517578156d (diff)
add DiffTreeToIndex
This is equivalent to `git diff --cached <treeish` or `diff --cached`.
Diffstat (limited to 'diff.go')
-rw-r--r--diff.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/diff.go b/diff.go
index 565fcee..9a7ac78 100644
--- a/diff.go
+++ b/diff.go
@@ -622,6 +622,36 @@ func (v *Repository) DiffTreeToWorkdir(oldTree *Tree, opts *DiffOptions) (*Diff,
return newDiffFromC(diffPtr), nil
}
+func (v *Repository) DiffTreeToIndex(oldTree *Tree, index *Index, opts *DiffOptions) (*Diff, error) {
+ var diffPtr *C.git_diff
+ var oldPtr *C.git_tree
+ var indexPtr *C.git_index
+
+ if oldTree != nil {
+ oldPtr = oldTree.cast_ptr
+ }
+
+ if index != nil {
+ indexPtr = index.ptr
+ }
+
+ copts, notifyData := diffOptionsToC(opts)
+ defer freeDiffOptions(copts)
+
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ ecode := C.git_diff_tree_to_index(&diffPtr, v.ptr, oldPtr, indexPtr, copts)
+ if ecode < 0 {
+ return nil, MakeGitError(ecode)
+ }
+
+ if notifyData != nil && notifyData.Diff != nil {
+ return notifyData.Diff, nil
+ }
+ return newDiffFromC(diffPtr), nil
+}
+
func (v *Repository) DiffTreeToWorkdirWithIndex(oldTree *Tree, opts *DiffOptions) (*Diff, error) {
var diffPtr *C.git_diff
var oldPtr *C.git_tree