Repository state

This commit is contained in:
Mark Probst 2015-03-04 11:32:56 -08:00
parent eec61815fb
commit 56ed0b22d7
2 changed files with 27 additions and 0 deletions

View File

@ -630,3 +630,25 @@ func (v *Repository) DefaultNoteRef() (string, error) {
return C.GoString(ptr), nil
}
type RepositoryState int
const (
RepositoryStateNone RepositoryState = C.GIT_REPOSITORY_STATE_NONE
RepositoryStateMerge RepositoryState = C.GIT_REPOSITORY_STATE_MERGE
RepositoryStateRevert RepositoryState = C.GIT_REPOSITORY_STATE_REVERT
RepositoryStateCherrypick RepositoryState = C.GIT_REPOSITORY_STATE_CHERRYPICK
RepositoryStateBisect RepositoryState = C.GIT_REPOSITORY_STATE_BISECT
RepositoryStateRebase RepositoryState = C.GIT_REPOSITORY_STATE_REBASE
RepositoryStateRebaseInteractive RepositoryState = C.GIT_REPOSITORY_STATE_REBASE_INTERACTIVE
RepositoryStateRebaseMerge RepositoryState = C.GIT_REPOSITORY_STATE_REBASE_MERGE
RepositoryStateApplyMailbox RepositoryState = C.GIT_REPOSITORY_STATE_APPLY_MAILBOX
RepositoryStateApplyMailboxOrRebase RepositoryState = C.GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE
)
func (r *Repository) State() RepositoryState {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
return RepositoryState(C.git_repository_state(r.ptr))
}

View File

@ -12,6 +12,11 @@ func TestStatusFile(t *testing.T) {
defer repo.Free()
defer os.RemoveAll(repo.Workdir())
state := repo.State()
if state != RepositoryStateNone {
t.Fatal("Incorrect repository state: ", state)
}
err := ioutil.WriteFile(path.Join(path.Dir(repo.Workdir()), "hello.txt"), []byte("Hello, World"), 0644)
checkFatal(t, err)