summaryrefslogtreecommitdiff
path: root/index.go
diff options
context:
space:
mode:
authorCarlos Martín Nieto <[email protected]>2015-05-19 15:21:49 +0200
committerCarlos Martín Nieto <[email protected]>2015-05-19 15:21:49 +0200
commit193deb7ae3cbc5d5a1f7f186aae6edb20bff950a (patch)
tree55f48583cec75d41265679ccad2075730ab2b786 /index.go
parentf7781c0e0004f76833c6be93409320b5c143e0c8 (diff)
parent72c19f73c9170720780839cd1561486e075d35a8 (diff)
Merge pull request #202 from libgit2/index-basics
Add a few basic index operations
Diffstat (limited to 'index.go')
-rw-r--r--index.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/index.go b/index.go
index 9f37f33..1a899f1 100644
--- a/index.go
+++ b/index.go
@@ -96,6 +96,30 @@ func NewIndex() (*Index, error) {
return &Index{ptr: ptr}, nil
}
+// OpenIndex creates a new index at the given path. If the file does
+// not exist it will be created when Write() is called.
+func OpenIndex(path string) (*Index, error) {
+ var ptr *C.git_index
+
+ var cpath = C.CString(path)
+ defer C.free(unsafe.Pointer(cpath))
+
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ if err := C.git_index_open(&ptr, cpath); err < 0 {
+ return nil, MakeGitError(err)
+ }
+
+ return &Index{ptr: ptr}, nil
+}
+
+// Path returns the index' path on disk or an empty string if it
+// exists only in memory.
+func (v *Index) Path() string {
+ return C.GoString(C.git_index_path(v.ptr))
+}
+
// Add adds or replaces the given entry to the index, making a copy of
// the data
func (v *Index) Add(entry *IndexEntry) error {
@@ -240,6 +264,20 @@ func (v *Index) WriteTreeTo(repo *Repository) (*Oid, error) {
return oid, nil
}
+// ReadTree replaces the contents of the index with those of the given
+// tree
+func (v *Index) ReadTree(tree *Tree) error {
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ ret := C.git_index_read_tree(v.ptr, tree.cast_ptr);
+ if ret < 0 {
+ return MakeGitError(ret)
+ }
+
+ return nil
+}
+
func (v *Index) WriteTree() (*Oid, error) {
oid := new(Oid)