nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: libgit2/git2go
Pull request #687 (2020-11-14 00:51:23)

Add ReferenceNormalizeName (#681)
(cherry picked from commit 2bd574b6bd75a044f526cf882161db08ac3cb633)


Patch:
diff --git a/reference.go b/reference.go
index b5f5e47..7b5e3c2 100644
--- a/reference.go
+++ b/reference.go
@@ -488,3 +488,42 @@ func ReferenceIsValidName(name string) bool {
 	}
 	return false
 }
+
+const (
+	// This should match GIT_REFNAME_MAX in src/refs.h
+	_refnameMaxLength = C.size_t(1024)
+)
+
+type ReferenceFormat uint
+
+const (
+	ReferenceFormatNormal           ReferenceFormat = C.GIT_REFERENCE_FORMAT_NORMAL
+	ReferenceFormatAllowOnelevel    ReferenceFormat = C.GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL
+	ReferenceFormatRefspecPattern   ReferenceFormat = C.GIT_REFERENCE_FORMAT_REFSPEC_PATTERN
+	ReferenceFormatRefspecShorthand ReferenceFormat = C.GIT_REFERENCE_FORMAT_REFSPEC_SHORTHAND
+)
+
+// ReferenceNormalizeName normalizes the reference name and checks validity.
+//
+// This will normalize the reference name by removing any leading slash '/'
+// characters and collapsing runs of adjacent slashes between name components
+// into a single slash.
+//
+// See git_reference_symbolic_create() for rules about valid names.
+func ReferenceNormalizeName(name string, flags ReferenceFormat) (string, error) {
+	cname := C.CString(name)
+	defer C.free(unsafe.Pointer(cname))
+
+	buf := (*C.char)(C.malloc(_refnameMaxLength))
+	defer C.free(unsafe.Pointer(buf))
+
+	runtime.LockOSThread()
+	defer runtime.UnlockOSThread()
+
+	ecode := C.git_reference_normalize_name(buf, _refnameMaxLength, cname, C.uint(flags))
+	if ecode < 0 {
+		return "", MakeGitError(ecode)
+	}
+
+	return C.GoString(buf), nil
+}


Test patch:
diff --git a/reference_test.go b/reference_test.go
index b6721e1..e42db41 100644
--- a/reference_test.go
+++ b/reference_test.go
@@ -224,6 +224,29 @@ func TestReferenceIsValidName(t *testing.T) {
 	}
 }
 
+func TestReferenceNormalizeName(t *testing.T) {
+	t.Parallel()
+
+	ref, err := ReferenceNormalizeName("refs/heads//master", ReferenceFormatNormal)
+	checkFatal(t, err)
+
+	if ref != "refs/heads/master" {
+		t.Errorf("ReferenceNormalizeName(%q) = %q; want %q", "refs/heads//master", ref, "refs/heads/master")
+	}
+
+	ref, err = ReferenceNormalizeName("master", ReferenceFormatAllowOnelevel|ReferenceFormatRefspecShorthand)
+	checkFatal(t, err)
+
+	if ref != "master" {
+		t.Errorf("ReferenceNormalizeName(%q) = %q; want %q", "master", ref, "master")
+	}
+
+	ref, err = ReferenceNormalizeName("foo^", ReferenceFormatNormal)
+	if !IsErrorCode(err, ErrInvalidSpec) {
+		t.Errorf("foo^ should be invalid")
+	}
+}
+
 func compareStringList(t *testing.T, expected, actual []string) {
 	for i, v := range expected {
 		if actual[i] != v {
Repository: libgit2/git2go
Pull request #688 (2020-11-14 00:51:24)

Add ReferenceNormalizeName (#681)
(cherry picked from commit 2bd574b6bd75a044f526cf882161db08ac3cb633)


Patch:
diff --git a/reference.go b/reference.go
index 12ecb74..3288c27 100644
--- a/reference.go
+++ b/reference.go
@@ -488,3 +488,42 @@ func ReferenceIsValidName(name string) bool {
 	}
 	return false
 }
+
+const (
+	// This should match GIT_REFNAME_MAX in src/refs.h
+	_refnameMaxLength = C.size_t(1024)
+)
+
+type ReferenceFormat uint
+
+const (
+	ReferenceFormatNormal           ReferenceFormat = C.GIT_REF_FORMAT_NORMAL
+	ReferenceFormatAllowOnelevel    ReferenceFormat = C.GIT_REF_FORMAT_ALLOW_ONELEVEL
+	ReferenceFormatRefspecPattern   ReferenceFormat = C.GIT_REF_FORMAT_REFSPEC_PATTERN
+	ReferenceFormatRefspecShorthand ReferenceFormat = C.GIT_REF_FORMAT_REFSPEC_SHORTHAND
+)
+
+// ReferenceNormalizeName normalizes the reference name and checks validity.
+//
+// This will normalize the reference name by removing any leading slash '/'
+// characters and collapsing runs of adjacent slashes between name components
+// into a single slash.
+//
+// See git_reference_symbolic_create() for rules about valid names.
+func ReferenceNormalizeName(name string, flags ReferenceFormat) (string, error) {
+	cname := C.CString(name)
+	defer C.free(unsafe.Pointer(cname))
+
+	buf := (*C.char)(C.malloc(_refnameMaxLength))
+	defer C.free(unsafe.Pointer(buf))
+
+	runtime.LockOSThread()
+	defer runtime.UnlockOSThread()
+
+	ecode := C.git_reference_normalize_name(buf, _refnameMaxLength, cname, C.uint(flags))
+	if ecode < 0 {
+		return "", MakeGitError(ecode)
+	}
+
+	return C.GoString(buf), nil
+}


Test patch:
diff --git a/reference_test.go b/reference_test.go
index b6721e1..e42db41 100644
--- a/reference_test.go
+++ b/reference_test.go
@@ -224,6 +224,29 @@ func TestReferenceIsValidName(t *testing.T) {
 	}
 }
 
+func TestReferenceNormalizeName(t *testing.T) {
+	t.Parallel()
+
+	ref, err := ReferenceNormalizeName("refs/heads//master", ReferenceFormatNormal)
+	checkFatal(t, err)
+
+	if ref != "refs/heads/master" {
+		t.Errorf("ReferenceNormalizeName(%q) = %q; want %q", "refs/heads//master", ref, "refs/heads/master")
+	}
+
+	ref, err = ReferenceNormalizeName("master", ReferenceFormatAllowOnelevel|ReferenceFormatRefspecShorthand)
+	checkFatal(t, err)
+
+	if ref != "master" {
+		t.Errorf("ReferenceNormalizeName(%q) = %q; want %q", "master", ref, "master")
+	}
+
+	ref, err = ReferenceNormalizeName("foo^", ReferenceFormatNormal)
+	if !IsErrorCode(err, ErrInvalidSpec) {
+		t.Errorf("foo^ should be invalid")
+	}
+}
+
 func compareStringList(t *testing.T, expected, actual []string) {
 	for i, v := range expected {
 		if actual[i] != v {
Repository: libgit2/git2go
Pull request #757 (2021-04-03 23:05:55)

Git repository item path
add wrapper for `git_repository_item_path`


Patch:
diff --git a/repository.go b/repository.go
index a6eb7f1..cb82fc3 100644
--- a/repository.go
+++ b/repository.go
@@ -739,5 +739,39 @@ func (r *Repository) RemoveMessage() error {
 	if cErr < 0 {
 		return MakeGitError(cErr)
 	}
-	return  nil
+	return nil
+}
+
+type RepositoryItem int
+
+const (
+	RepositoryItemGitDir     RepositoryItem = C.GIT_REPOSITORY_ITEM_GITDIR
+	RepositoryItemWorkDir    RepositoryItem = C.GIT_REPOSITORY_ITEM_WORKDIR
+	RepositoryItemCommonDir  RepositoryItem = C.GIT_REPOSITORY_ITEM_COMMONDIR
+	RepositoryItemIndex      RepositoryItem = C.GIT_REPOSITORY_ITEM_INDEX
+	RepositoryItemObjects    RepositoryItem = C.GIT_REPOSITORY_ITEM_OBJECTS
+	RepositoryItemRefs       RepositoryItem = C.GIT_REPOSITORY_ITEM_REFS
+	RepositoryItemPackedRefs RepositoryItem = C.GIT_REPOSITORY_ITEM_PACKED_REFS
+	RepositoryItemRemotes    RepositoryItem = C.GIT_REPOSITORY_ITEM_REMOTES
+	RepositoryItemConfig     RepositoryItem = C.GIT_REPOSITORY_ITEM_CONFIG
+	RepositoryItemInfo       RepositoryItem = C.GIT_REPOSITORY_ITEM_INFO
+	RepositoryItemHooks      RepositoryItem = C.GIT_REPOSITORY_ITEM_HOOKS
+	RepositoryItemLogs       RepositoryItem = C.GIT_REPOSITORY_ITEM_LOGS
+	RepositoryItemModules    RepositoryItem = C.GIT_REPOSITORY_ITEM_MODULES
+	RepositoryItemWorkTrees  RepositoryItem = C.GIT_REPOSITORY_ITEM_WORKTREES
+)
+
+func (r *Repository) ItemPath(item RepositoryItem) (string, error) {
+	var c_buf C.git_buf
+	defer C.git_buf_dispose(&c_buf)
+
+	runtime.LockOSThread()
+	defer runtime.UnlockOSThread()
+
+	ret := C.git_repository_item_path(&c_buf, r.ptr, C.git_repository_item_t(item))
+	runtime.KeepAlive(r)
+	if ret < 0 {
+		return "", MakeGitError(ret)
+	}
+	return C.GoString(c_buf.ptr), nil
 }


Test patch:
diff --git a/repository_test.go b/repository_test.go
index 5a0f920..e403aa9 100644
--- a/repository_test.go
+++ b/repository_test.go
@@ -92,3 +92,14 @@ func TestRepositorySetConfig(t *testing.T) {
 		t.Fatal("result must be true")
 	}
 }
+
+func TestRepositoryItemPath(t *testing.T) {
+	repo := createTestRepo(t)
+	defer cleanupTestRepo(t, repo)
+
+	gitDir, err := repo.ItemPath(RepositoryItemGitDir)
+	checkFatal(t, err)
+	if gitDir == "" {
+		t.Error("expected not empty gitDir")
+	}
+}
Repository: libgit2/git2go
Pull request #759 (2021-04-03 23:52:50)

Git repository item path (#757)
add wrapper for `git_repository_item_path`

(cherry picked from commit a4d202ed7b025331ee4a63ebc38f62519cee4750)


Patch:
diff --git a/repository.go b/repository.go
index a6eb7f1..cb82fc3 100644
--- a/repository.go
+++ b/repository.go
@@ -739,5 +739,39 @@ func (r *Repository) RemoveMessage() error {
 	if cErr < 0 {
 		return MakeGitError(cErr)
 	}
-	return  nil
+	return nil
+}
+
+type RepositoryItem int
+
+const (
+	RepositoryItemGitDir     RepositoryItem = C.GIT_REPOSITORY_ITEM_GITDIR
+	RepositoryItemWorkDir    RepositoryItem = C.GIT_REPOSITORY_ITEM_WORKDIR
+	RepositoryItemCommonDir  RepositoryItem = C.GIT_REPOSITORY_ITEM_COMMONDIR
+	RepositoryItemIndex      RepositoryItem = C.GIT_REPOSITORY_ITEM_INDEX
+	RepositoryItemObjects    RepositoryItem = C.GIT_REPOSITORY_ITEM_OBJECTS
+	RepositoryItemRefs       RepositoryItem = C.GIT_REPOSITORY_ITEM_REFS
+	RepositoryItemPackedRefs RepositoryItem = C.GIT_REPOSITORY_ITEM_PACKED_REFS
+	RepositoryItemRemotes    RepositoryItem = C.GIT_REPOSITORY_ITEM_REMOTES
+	RepositoryItemConfig     RepositoryItem = C.GIT_REPOSITORY_ITEM_CONFIG
+	RepositoryItemInfo       RepositoryItem = C.GIT_REPOSITORY_ITEM_INFO
+	RepositoryItemHooks      RepositoryItem = C.GIT_REPOSITORY_ITEM_HOOKS
+	RepositoryItemLogs       RepositoryItem = C.GIT_REPOSITORY_ITEM_LOGS
+	RepositoryItemModules    RepositoryItem = C.GIT_REPOSITORY_ITEM_MODULES
+	RepositoryItemWorkTrees  RepositoryItem = C.GIT_REPOSITORY_ITEM_WORKTREES
+)
+
+func (r *Repository) ItemPath(item RepositoryItem) (string, error) {
+	var c_buf C.git_buf
+	defer C.git_buf_dispose(&c_buf)
+
+	runtime.LockOSThread()
+	defer runtime.UnlockOSThread()
+
+	ret := C.git_repository_item_path(&c_buf, r.ptr, C.git_repository_item_t(item))
+	runtime.KeepAlive(r)
+	if ret < 0 {
+		return "", MakeGitError(ret)
+	}
+	return C.GoString(c_buf.ptr), nil
 }


Test patch:
diff --git a/repository_test.go b/repository_test.go
index 5a0f920..e403aa9 100644
--- a/repository_test.go
+++ b/repository_test.go
@@ -92,3 +92,14 @@ func TestRepositorySetConfig(t *testing.T) {
 		t.Fatal("result must be true")
 	}
 }
+
+func TestRepositoryItemPath(t *testing.T) {
+	repo := createTestRepo(t)
+	defer cleanupTestRepo(t, repo)
+
+	gitDir, err := repo.ItemPath(RepositoryItemGitDir)
+	checkFatal(t, err)
+	if gitDir == "" {
+		t.Error("expected not empty gitDir")
+	}
+}
Repository: libgit2/git2go
Pull request #760 (2021-04-03 23:52:51)

Git repository item path (#757)
add wrapper for `git_repository_item_path`

(cherry picked from commit a4d202ed7b025331ee4a63ebc38f62519cee4750)


Patch:
diff --git a/repository.go b/repository.go
index 3113b3c..e0f94ae 100644
--- a/repository.go
+++ b/repository.go
@@ -733,5 +733,39 @@ func (r *Repository) RemoveMessage() error {
 	if cErr < 0 {
 		return MakeGitError(cErr)
 	}
-	return  nil
+	return nil
+}
+
+type RepositoryItem int
+
+const (
+	RepositoryItemGitDir     RepositoryItem = C.GIT_REPOSITORY_ITEM_GITDIR
+	RepositoryItemWorkDir    RepositoryItem = C.GIT_REPOSITORY_ITEM_WORKDIR
+	RepositoryItemCommonDir  RepositoryItem = C.GIT_REPOSITORY_ITEM_COMMONDIR
+	RepositoryItemIndex      RepositoryItem = C.GIT_REPOSITORY_ITEM_INDEX
+	RepositoryItemObjects    RepositoryItem = C.GIT_REPOSITORY_ITEM_OBJECTS
+	RepositoryItemRefs       RepositoryItem = C.GIT_REPOSITORY_ITEM_REFS
+	RepositoryItemPackedRefs RepositoryItem = C.GIT_REPOSITORY_ITEM_PACKED_REFS
+	RepositoryItemRemotes    RepositoryItem = C.GIT_REPOSITORY_ITEM_REMOTES
+	RepositoryItemConfig     RepositoryItem = C.GIT_REPOSITORY_ITEM_CONFIG
+	RepositoryItemInfo       RepositoryItem = C.GIT_REPOSITORY_ITEM_INFO
+	RepositoryItemHooks      RepositoryItem = C.GIT_REPOSITORY_ITEM_HOOKS
+	RepositoryItemLogs       RepositoryItem = C.GIT_REPOSITORY_ITEM_LOGS
+	RepositoryItemModules    RepositoryItem = C.GIT_REPOSITORY_ITEM_MODULES
+	RepositoryItemWorkTrees  RepositoryItem = C.GIT_REPOSITORY_ITEM_WORKTREES
+)
+
+func (r *Repository) ItemPath(item RepositoryItem) (string, error) {
+	var c_buf C.git_buf
+	defer C.git_buf_dispose(&c_buf)
+
+	runtime.LockOSThread()
+	defer runtime.UnlockOSThread()
+
+	ret := C.git_repository_item_path(&c_buf, r.ptr, C.git_repository_item_t(item))
+	runtime.KeepAlive(r)
+	if ret < 0 {
+		return "", MakeGitError(ret)
+	}
+	return C.GoString(c_buf.ptr), nil
 }


Test patch:
diff --git a/repository_test.go b/repository_test.go
index 5a0f920..e403aa9 100644
--- a/repository_test.go
+++ b/repository_test.go
@@ -92,3 +92,14 @@ func TestRepositorySetConfig(t *testing.T) {
 		t.Fatal("result must be true")
 	}
 }
+
+func TestRepositoryItemPath(t *testing.T) {
+	repo := createTestRepo(t)
+	defer cleanupTestRepo(t, repo)
+
+	gitDir, err := repo.ItemPath(RepositoryItemGitDir)
+	checkFatal(t, err)
+	if gitDir == "" {
+		t.Error("expected not empty gitDir")
+	}
+}
Repository: libgit2/git2go
Pull request #762 (2021-04-04 01:45:27)

fix buldled static build on Windows/MinGW (#761)
seems like need more libraries in LDFLAGS:

* ws2_32 for socket, connect, htonl, etc
* ole32 for CoInitializeEx
* rpcrt4 for UuidCreate
* crypt32 for CertFreeCertificateContext

(cherry picked from commit 0d7c8dadb465a0236d0f130a0cfd5179502f191d)


Patch:
diff --git a/Build_bundled_static.go b/Build_bundled_static.go
index 8076dbe..f467c5c 100644
--- a/Build_bundled_static.go
+++ b/Build_bundled_static.go
@@ -4,7 +4,7 @@ package git
 
 /*
 #cgo windows CFLAGS: -I${SRCDIR}/static-build/install/include/
-#cgo windows LDFLAGS: -L${SRCDIR}/static-build/install/lib/ -lgit2 -lwinhttp
+#cgo windows LDFLAGS: -L${SRCDIR}/static-build/install/lib/ -lgit2 -lwinhttp -lws2_32 -lole32 -lrpcrt4 -lcrypt32
 #cgo !windows pkg-config: --static ${SRCDIR}/static-build/install/lib/pkgconfig/libgit2.pc
 #cgo CFLAGS: -DLIBGIT2_STATIC
 #include <git2.h>
diff --git a/repository.go b/repository.go
index a6eb7f1..cb82fc3 100644
--- a/repository.go
+++ b/repository.go
@@ -739,5 +739,39 @@ func (r *Repository) RemoveMessage() error {
 	if cErr < 0 {
 		return MakeGitError(cErr)
 	}
-	return  nil
+	return nil
+}
+
+type RepositoryItem int
+
+const (
+	RepositoryItemGitDir     RepositoryItem = C.GIT_REPOSITORY_ITEM_GITDIR
+	RepositoryItemWorkDir    RepositoryItem = C.GIT_REPOSITORY_ITEM_WORKDIR
+	RepositoryItemCommonDir  RepositoryItem = C.GIT_REPOSITORY_ITEM_COMMONDIR
+	RepositoryItemIndex      RepositoryItem = C.GIT_REPOSITORY_ITEM_INDEX
+	RepositoryItemObjects    RepositoryItem = C.GIT_REPOSITORY_ITEM_OBJECTS
+	RepositoryItemRefs       RepositoryItem = C.GIT_REPOSITORY_ITEM_REFS
+	RepositoryItemPackedRefs RepositoryItem = C.GIT_REPOSITORY_ITEM_PACKED_REFS
+	RepositoryItemRemotes    RepositoryItem = C.GIT_REPOSITORY_ITEM_REMOTES
+	RepositoryItemConfig     RepositoryItem = C.GIT_REPOSITORY_ITEM_CONFIG
+	RepositoryItemInfo       RepositoryItem = C.GIT_REPOSITORY_ITEM_INFO
+	RepositoryItemHooks      RepositoryItem = C.GIT_REPOSITORY_ITEM_HOOKS
+	RepositoryItemLogs       RepositoryItem = C.GIT_REPOSITORY_ITEM_LOGS
+	RepositoryItemModules    RepositoryItem = C.GIT_REPOSITORY_ITEM_MODULES
+	RepositoryItemWorkTrees  RepositoryItem = C.GIT_REPOSITORY_ITEM_WORKTREES
+)
+
+func (r *Repository) ItemPath(item RepositoryItem) (string, error) {
+	var c_buf C.git_buf
+	defer C.git_buf_dispose(&c_buf)
+
+	runtime.LockOSThread()
+	defer runtime.UnlockOSThread()
+
+	ret := C.git_repository_item_path(&c_buf, r.ptr, C.git_repository_item_t(item))
+	runtime.KeepAlive(r)
+	if ret < 0 {
+		return "", MakeGitError(ret)
+	}
+	return C.GoString(c_buf.ptr), nil
 }


Test patch:
diff --git a/repository_test.go b/repository_test.go
index 5a0f920..e403aa9 100644
--- a/repository_test.go
+++ b/repository_test.go
@@ -92,3 +92,14 @@ func TestRepositorySetConfig(t *testing.T) {
 		t.Fatal("result must be true")
 	}
 }
+
+func TestRepositoryItemPath(t *testing.T) {
+	repo := createTestRepo(t)
+	defer cleanupTestRepo(t, repo)
+
+	gitDir, err := repo.ItemPath(RepositoryItemGitDir)
+	checkFatal(t, err)
+	if gitDir == "" {
+		t.Error("expected not empty gitDir")
+	}
+}
Repository: libgit2/git2go
Pull request #763 (2021-04-04 01:45:27)

fix buldled static build on Windows/MinGW (#761)
seems like need more libraries in LDFLAGS:

* ws2_32 for socket, connect, htonl, etc
* ole32 for CoInitializeEx
* rpcrt4 for UuidCreate
* crypt32 for CertFreeCertificateContext

(cherry picked from commit 0d7c8dadb465a0236d0f130a0cfd5179502f191d)


Patch:
diff --git a/Build_bundled_static.go b/Build_bundled_static.go
index e66f425..1e1cb36 100644
--- a/Build_bundled_static.go
+++ b/Build_bundled_static.go
@@ -4,7 +4,7 @@ package git
 
 /*
 #cgo windows CFLAGS: -I${SRCDIR}/static-build/install/include/
-#cgo windows LDFLAGS: -L${SRCDIR}/static-build/install/lib/ -lgit2 -lwinhttp
+#cgo windows LDFLAGS: -L${SRCDIR}/static-build/install/lib/ -lgit2 -lwinhttp -lws2_32 -lole32 -lrpcrt4 -lcrypt32
 #cgo !windows pkg-config: --static ${SRCDIR}/static-build/install/lib/pkgconfig/libgit2.pc
 #cgo CFLAGS: -DLIBGIT2_STATIC
 #include <git2.h>
diff --git a/repository.go b/repository.go
index 1ee9b36..c17b4f4 100644
--- a/repository.go
+++ b/repository.go
@@ -735,3 +735,37 @@ func (r *Repository) RemoveMessage() error {
 	}
 	return nil
 }
+
+type RepositoryItem int
+
+const (
+	RepositoryItemGitDir     RepositoryItem = C.GIT_REPOSITORY_ITEM_GITDIR
+	RepositoryItemWorkDir    RepositoryItem = C.GIT_REPOSITORY_ITEM_WORKDIR
+	RepositoryItemCommonDir  RepositoryItem = C.GIT_REPOSITORY_ITEM_COMMONDIR
+	RepositoryItemIndex      RepositoryItem = C.GIT_REPOSITORY_ITEM_INDEX
+	RepositoryItemObjects    RepositoryItem = C.GIT_REPOSITORY_ITEM_OBJECTS
+	RepositoryItemRefs       RepositoryItem = C.GIT_REPOSITORY_ITEM_REFS
+	RepositoryItemPackedRefs RepositoryItem = C.GIT_REPOSITORY_ITEM_PACKED_REFS
+	RepositoryItemRemotes    RepositoryItem = C.GIT_REPOSITORY_ITEM_REMOTES
+	RepositoryItemConfig     RepositoryItem = C.GIT_REPOSITORY_ITEM_CONFIG
+	RepositoryItemInfo       RepositoryItem = C.GIT_REPOSITORY_ITEM_INFO
+	RepositoryItemHooks      RepositoryItem = C.GIT_REPOSITORY_ITEM_HOOKS
+	RepositoryItemLogs       RepositoryItem = C.GIT_REPOSITORY_ITEM_LOGS
+	RepositoryItemModules    RepositoryItem = C.GIT_REPOSITORY_ITEM_MODULES
+	RepositoryItemWorkTrees  RepositoryItem = C.GIT_REPOSITORY_ITEM_WORKTREES
+)
+
+func (r *Repository) ItemPath(item RepositoryItem) (string, error) {
+	var c_buf C.git_buf
+	defer C.git_buf_free(&c_buf)
+
+	runtime.LockOSThread()
+	defer runtime.UnlockOSThread()
+
+	ret := C.git_repository_item_path(&c_buf, r.ptr, C.git_repository_item_t(item))
+	runtime.KeepAlive(r)
+	if ret < 0 {
+		return "", MakeGitError(ret)
+	}
+	return C.GoString(c_buf.ptr), nil
+}


Test patch:
diff --git a/repository_test.go b/repository_test.go
index 5a0f920..e403aa9 100644
--- a/repository_test.go
+++ b/repository_test.go
@@ -92,3 +92,14 @@ func TestRepositorySetConfig(t *testing.T) {
 		t.Fatal("result must be true")
 	}
 }
+
+func TestRepositoryItemPath(t *testing.T) {
+	repo := createTestRepo(t)
+	defer cleanupTestRepo(t, repo)
+
+	gitDir, err := repo.ItemPath(RepositoryItemGitDir)
+	checkFatal(t, err)
+	if gitDir == "" {
+		t.Error("expected not empty gitDir")
+	}
+}
Repository: libgit2/git2go
Pull request #764 (2021-04-04 01:45:28)

fix buldled static build on Windows/MinGW (#761)
seems like need more libraries in LDFLAGS:

* ws2_32 for socket, connect, htonl, etc
* ole32 for CoInitializeEx
* rpcrt4 for UuidCreate
* crypt32 for CertFreeCertificateContext

(cherry picked from commit 0d7c8dadb465a0236d0f130a0cfd5179502f191d)


Patch:
diff --git a/Build_bundled_static.go b/Build_bundled_static.go
index 866c77e..c6490a4 100644
--- a/Build_bundled_static.go
+++ b/Build_bundled_static.go
@@ -4,7 +4,7 @@ package git
 
 /*
 #cgo windows CFLAGS: -I${SRCDIR}/static-build/install/include/
-#cgo windows LDFLAGS: -L${SRCDIR}/static-build/install/lib/ -lgit2 -lwinhttp
+#cgo windows LDFLAGS: -L${SRCDIR}/static-build/install/lib/ -lgit2 -lwinhttp -lws2_32 -lole32 -lrpcrt4 -lcrypt32
 #cgo !windows pkg-config: --static ${SRCDIR}/static-build/install/lib/pkgconfig/libgit2.pc
 #cgo CFLAGS: -DLIBGIT2_STATIC
 #include <git2.h>
diff --git a/repository.go b/repository.go
index 3113b3c..e0f94ae 100644
--- a/repository.go
+++ b/repository.go
@@ -733,5 +733,39 @@ func (r *Repository) RemoveMessage() error {
 	if cErr < 0 {
 		return MakeGitError(cErr)
 	}
-	return  nil
+	return nil
+}
+
+type RepositoryItem int
+
+const (
+	RepositoryItemGitDir     RepositoryItem = C.GIT_REPOSITORY_ITEM_GITDIR
+	RepositoryItemWorkDir    RepositoryItem = C.GIT_REPOSITORY_ITEM_WORKDIR
+	RepositoryItemCommonDir  RepositoryItem = C.GIT_REPOSITORY_ITEM_COMMONDIR
+	RepositoryItemIndex      RepositoryItem = C.GIT_REPOSITORY_ITEM_INDEX
+	RepositoryItemObjects    RepositoryItem = C.GIT_REPOSITORY_ITEM_OBJECTS
+	RepositoryItemRefs       RepositoryItem = C.GIT_REPOSITORY_ITEM_REFS
+	RepositoryItemPackedRefs RepositoryItem = C.GIT_REPOSITORY_ITEM_PACKED_REFS
+	RepositoryItemRemotes    RepositoryItem = C.GIT_REPOSITORY_ITEM_REMOTES
+	RepositoryItemConfig     RepositoryItem = C.GIT_REPOSITORY_ITEM_CONFIG
+	RepositoryItemInfo       RepositoryItem = C.GIT_REPOSITORY_ITEM_INFO
+	RepositoryItemHooks      RepositoryItem = C.GIT_REPOSITORY_ITEM_HOOKS
+	RepositoryItemLogs       RepositoryItem = C.GIT_REPOSITORY_ITEM_LOGS
+	RepositoryItemModules    RepositoryItem = C.GIT_REPOSITORY_ITEM_MODULES
+	RepositoryItemWorkTrees  RepositoryItem = C.GIT_REPOSITORY_ITEM_WORKTREES
+)
+
+func (r *Repository) ItemPath(item RepositoryItem) (string, error) {
+	var c_buf C.git_buf
+	defer C.git_buf_dispose(&c_buf)
+
+	runtime.LockOSThread()
+	defer runtime.UnlockOSThread()
+
+	ret := C.git_repository_item_path(&c_buf, r.ptr, C.git_repository_item_t(item))
+	runtime.KeepAlive(r)
+	if ret < 0 {
+		return "", MakeGitError(ret)
+	}
+	return C.GoString(c_buf.ptr), nil
 }


Test patch:
diff --git a/repository_test.go b/repository_test.go
index 5a0f920..e403aa9 100644
--- a/repository_test.go
+++ b/repository_test.go
@@ -92,3 +92,14 @@ func TestRepositorySetConfig(t *testing.T) {
 		t.Fatal("result must be true")
 	}
 }
+
+func TestRepositoryItemPath(t *testing.T) {
+	repo := createTestRepo(t)
+	defer cleanupTestRepo(t, repo)
+
+	gitDir, err := repo.ItemPath(RepositoryItemGitDir)
+	checkFatal(t, err)
+	if gitDir == "" {
+		t.Error("expected not empty gitDir")
+	}
+}