Implement git_index_remove_directory in index wrapper #351
16
index.go
16
index.go
|
@ -278,6 +278,22 @@ func (v *Index) RemoveByPath(path string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RemoveDirectory removes all entries from the index under a given directory.
|
||||||
|
func (v *Index) RemoveDirectory(dir string, stage int) error {
|
||||||
|
cstr := C.CString(dir)
|
||||||
|
defer C.free(unsafe.Pointer(cstr))
|
||||||
|
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
ret := C.git_index_remove_directory(v.ptr, cstr, C.int(stage))
|
||||||
|
if ret < 0 {
|
||||||
|
return MakeGitError(ret)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (v *Index) WriteTreeTo(repo *Repository) (*Oid, error) {
|
func (v *Index) WriteTreeTo(repo *Repository) (*Oid, error) {
|
||||||
oid := new(Oid)
|
oid := new(Oid)
|
||||||
|
|
||||||
|
|
|
@ -105,6 +105,46 @@ func TestIndexAddAndWriteTreeTo(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIndexRemoveDirectory(t *testing.T) {
|
||||||
|
repo := createTestRepo(t)
|
||||||
|
defer cleanupTestRepo(t, repo)
|
||||||
|
|
||||||
|
odb, err := repo.Odb()
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
blobID, err := odb.Write([]byte("fou\n"), ObjectBlob)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
idx, err := NewIndex()
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
entryCount := idx.EntryCount()
|
||||||
|
if entryCount != 0 {
|
||||||
|
t.Fatal("Index should count 0 entry")
|
||||||
|
}
|
||||||
|
|
||||||
|
entry := IndexEntry{
|
||||||
|
Path: "path/to/LISEZ_MOI",
|
||||||
|
Id: blobID,
|
||||||
|
Mode: FilemodeBlob,
|
||||||
|
}
|
||||||
|
|
||||||
|
err = idx.Add(&entry)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
entryCount = idx.EntryCount()
|
||||||
|
if entryCount != 1 {
|
||||||
|
t.Fatal("Index should count 1 entry")
|
||||||
|
}
|
||||||
|
|
||||||
|
err = idx.RemoveDirectory("path", 0)
|
||||||
|
|
||||||
|
entryCount = idx.EntryCount()
|
||||||
|
if entryCount != 0 {
|
||||||
|
t.Fatal("Index should count 0 entry")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestIndexAddAllNoCallback(t *testing.T) {
|
func TestIndexAddAllNoCallback(t *testing.T) {
|
||||||
repo := createTestRepo(t)
|
repo := createTestRepo(t)
|
||||||
defer cleanupTestRepo(t, repo)
|
defer cleanupTestRepo(t, repo)
|
||||||
|
|
Loading…
Reference in New Issue