Index: Add Path() accessor
This commit is contained in:
parent
d7a0495000
commit
72c19f73c9
6
index.go
6
index.go
|
@ -114,6 +114,12 @@ func OpenIndex(path string) (*Index, error) {
|
||||||
return &Index{ptr: ptr}, nil
|
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
|
// Add adds or replaces the given entry to the index, making a copy of
|
||||||
// the data
|
// the data
|
||||||
func (v *Index) Add(entry *IndexEntry) error {
|
func (v *Index) Add(entry *IndexEntry) error {
|
||||||
|
|
|
@ -83,6 +83,10 @@ func TestIndexAddAndWriteTreeTo(t *testing.T) {
|
||||||
idx, err := NewIndex()
|
idx, err := NewIndex()
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
if idx.Path() != "" {
|
||||||
|
t.Fatal("in-memory repo has a path")
|
||||||
|
}
|
||||||
|
|
||||||
entry := IndexEntry{
|
entry := IndexEntry{
|
||||||
Path: "README",
|
Path: "README",
|
||||||
Id: blobID,
|
Id: blobID,
|
||||||
|
@ -163,6 +167,10 @@ func TestIndexOpen(t *testing.T) {
|
||||||
idx, err := OpenIndex(path)
|
idx, err := OpenIndex(path)
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
if path != idx.Path() {
|
||||||
|
t.Fatalf("mismatched index paths, expected %v, got %v", path, idx.Path())
|
||||||
|
}
|
||||||
|
|
||||||
err = idx.Write()
|
err = idx.Write()
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue