add StatusFile function
This commit is contained in:
parent
a093e20a88
commit
8fd7c2c609
13
status.go
13
status.go
|
@ -20,7 +20,7 @@ const (
|
||||||
StatusIndexRenamed = C.GIT_STATUS_INDEX_RENAMED
|
StatusIndexRenamed = C.GIT_STATUS_INDEX_RENAMED
|
||||||
StatusIndexTypeChange = C.GIT_STATUS_INDEX_TYPECHANGE
|
StatusIndexTypeChange = C.GIT_STATUS_INDEX_TYPECHANGE
|
||||||
StatusWtNew = C.GIT_STATUS_WT_NEW
|
StatusWtNew = C.GIT_STATUS_WT_NEW
|
||||||
StatusWtModified = C.GIT_STATUS_WT_NEW
|
StatusWtModified = C.GIT_STATUS_WT_MODIFIED
|
||||||
StatusWtDeleted = C.GIT_STATUS_WT_DELETED
|
StatusWtDeleted = C.GIT_STATUS_WT_DELETED
|
||||||
StatusWtTypeChange = C.GIT_STATUS_WT_TYPECHANGE
|
StatusWtTypeChange = C.GIT_STATUS_WT_TYPECHANGE
|
||||||
StatusWtRenamed = C.GIT_STATUS_WT_RENAMED
|
StatusWtRenamed = C.GIT_STATUS_WT_RENAMED
|
||||||
|
@ -157,3 +157,14 @@ func (v *Repository) StatusList(opts *StatusOptions) (*StatusList, error) {
|
||||||
}
|
}
|
||||||
return newStatusListFromC(ptr), nil
|
return newStatusListFromC(ptr), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (v *Repository) StatusFile(path string) (Status, error) {
|
||||||
|
var statusFlags C.uint
|
||||||
|
cPath := C.CString(path)
|
||||||
|
ret := C.git_status_file(&statusFlags, v.ptr, cPath)
|
||||||
|
if ret < 0 {
|
||||||
|
return 0, MakeGitError(ret)
|
||||||
|
}
|
||||||
|
return Status(statusFlags), nil
|
||||||
|
}
|
||||||
|
|
|
@ -7,12 +7,28 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestStatusFile(t *testing.T) {
|
||||||
|
repo := createTestRepo(t)
|
||||||
|
defer repo.Free()
|
||||||
|
defer os.RemoveAll(repo.Workdir())
|
||||||
|
|
||||||
|
err := ioutil.WriteFile(path.Join(path.Dir(repo.Workdir()), "hello.txt"), []byte("Hello, World"), 0644)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
status, err := repo.StatusFile("hello.txt")
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
if status != StatusWtNew {
|
||||||
|
t.Fatal("Incorrect status flags: ", status)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestEntryCount(t *testing.T) {
|
func TestEntryCount(t *testing.T) {
|
||||||
repo := createTestRepo(t)
|
repo := createTestRepo(t)
|
||||||
defer repo.Free()
|
defer repo.Free()
|
||||||
defer os.RemoveAll(repo.Workdir())
|
defer os.RemoveAll(repo.Workdir())
|
||||||
|
|
||||||
err := ioutil.WriteFile(path.Join(path.Dir(repo.Path()), "hello.txt"), []byte("Hello, World"), 0644)
|
err := ioutil.WriteFile(path.Join(path.Dir(repo.Workdir()), "hello.txt"), []byte("Hello, World"), 0644)
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
statusList, err := repo.StatusList(nil)
|
statusList, err := repo.StatusList(nil)
|
||||||
|
|
Loading…
Reference in New Issue