summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <[email protected]>2015-05-19 15:05:00 +0200
committerCarlos Martín Nieto <[email protected]>2015-05-19 15:05:00 +0200
commit72c19f73c9170720780839cd1561486e075d35a8 (patch)
tree55f48583cec75d41265679ccad2075730ab2b786
parentd7a0495000e35d06993605a9a31a5f9823292f8a (diff)
Index: Add Path() accessor
-rw-r--r--index.go6
-rw-r--r--index_test.go8
2 files changed, 14 insertions, 0 deletions
diff --git a/index.go b/index.go
index 2082ebd..1a899f1 100644
--- a/index.go
+++ b/index.go
@@ -114,6 +114,12 @@ func OpenIndex(path string) (*Index, error) {
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 {
diff --git a/index_test.go b/index_test.go
index 9b54945..9283b83 100644
--- a/index_test.go
+++ b/index_test.go
@@ -83,6 +83,10 @@ func TestIndexAddAndWriteTreeTo(t *testing.T) {
idx, err := NewIndex()
checkFatal(t, err)
+ if idx.Path() != "" {
+ t.Fatal("in-memory repo has a path")
+ }
+
entry := IndexEntry{
Path: "README",
Id: blobID,
@@ -163,6 +167,10 @@ func TestIndexOpen(t *testing.T) {
idx, err := OpenIndex(path)
checkFatal(t, err)
+ if path != idx.Path() {
+ t.Fatalf("mismatched index paths, expected %v, got %v", path, idx.Path())
+ }
+
err = idx.Write()
checkFatal(t, err)