Skip to content

Commit a4d202e

Browse files
Git repository item path (#757)
add wrapper for `git_repository_item_path`
1 parent aeb22bc commit a4d202e

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

repository.go

+35-1
Original file line numberDiff line numberDiff line change
@@ -739,5 +739,39 @@ func (r *Repository) RemoveMessage() error {
739739
if cErr < 0 {
740740
return MakeGitError(cErr)
741741
}
742-
return nil
742+
return nil
743+
}
744+
745+
type RepositoryItem int
746+
747+
const (
748+
RepositoryItemGitDir RepositoryItem = C.GIT_REPOSITORY_ITEM_GITDIR
749+
RepositoryItemWorkDir RepositoryItem = C.GIT_REPOSITORY_ITEM_WORKDIR
750+
RepositoryItemCommonDir RepositoryItem = C.GIT_REPOSITORY_ITEM_COMMONDIR
751+
RepositoryItemIndex RepositoryItem = C.GIT_REPOSITORY_ITEM_INDEX
752+
RepositoryItemObjects RepositoryItem = C.GIT_REPOSITORY_ITEM_OBJECTS
753+
RepositoryItemRefs RepositoryItem = C.GIT_REPOSITORY_ITEM_REFS
754+
RepositoryItemPackedRefs RepositoryItem = C.GIT_REPOSITORY_ITEM_PACKED_REFS
755+
RepositoryItemRemotes RepositoryItem = C.GIT_REPOSITORY_ITEM_REMOTES
756+
RepositoryItemConfig RepositoryItem = C.GIT_REPOSITORY_ITEM_CONFIG
757+
RepositoryItemInfo RepositoryItem = C.GIT_REPOSITORY_ITEM_INFO
758+
RepositoryItemHooks RepositoryItem = C.GIT_REPOSITORY_ITEM_HOOKS
759+
RepositoryItemLogs RepositoryItem = C.GIT_REPOSITORY_ITEM_LOGS
760+
RepositoryItemModules RepositoryItem = C.GIT_REPOSITORY_ITEM_MODULES
761+
RepositoryItemWorkTrees RepositoryItem = C.GIT_REPOSITORY_ITEM_WORKTREES
762+
)
763+
764+
func (r *Repository) ItemPath(item RepositoryItem) (string, error) {
765+
var c_buf C.git_buf
766+
defer C.git_buf_dispose(&c_buf)
767+
768+
runtime.LockOSThread()
769+
defer runtime.UnlockOSThread()
770+
771+
ret := C.git_repository_item_path(&c_buf, r.ptr, C.git_repository_item_t(item))
772+
runtime.KeepAlive(r)
773+
if ret < 0 {
774+
return "", MakeGitError(ret)
775+
}
776+
return C.GoString(c_buf.ptr), nil
743777
}

repository_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,14 @@ func TestRepositorySetConfig(t *testing.T) {
9292
t.Fatal("result must be true")
9393
}
9494
}
95+
96+
func TestRepositoryItemPath(t *testing.T) {
97+
repo := createTestRepo(t)
98+
defer cleanupTestRepo(t, repo)
99+
100+
gitDir, err := repo.ItemPath(RepositoryItemGitDir)
101+
checkFatal(t, err)
102+
if gitDir == "" {
103+
t.Error("expected not empty gitDir")
104+
}
105+
}

0 commit comments

Comments
 (0)