Skip to content

Commit b989a83

Browse files
committed
fix: skip the owner validation during parse the git source info
Signed-off-by: chlins <chlins.zhang@gmail.com>
1 parent 6b5f9c9 commit b989a83

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

pkg/source/git_libgit2.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,34 @@ package source
2020

2121
import (
2222
"fmt"
23+
"path/filepath"
2324

2425
git2go "github.com/libgit2/git2go/v34"
2526
)
2627

2728
type git struct{}
2829

2930
func (g *git) Parse(workspace string) (*Info, error) {
31+
absWorkspace, err := filepath.Abs(workspace)
32+
if err != nil {
33+
return nil, fmt.Errorf("failed to get absolute path of workspace: %w", err)
34+
}
35+
// Skip the owner verification as we only need to retrieve some metadata,
36+
// set the environment variable to configure it because don't found direct function or option in git2go.
37+
// os.Setenv("GIT_CONFIG_COUNT", "1")
38+
// os.Setenv("GIT_CONFIG_KEY_0", "safe.directory")
39+
// os.Setenv("GIT_CONFIG_VALUE_0", absWorkspace)
40+
//
41+
config, err := git2go.OpenDefault()
42+
if err != nil {
43+
return nil, fmt.Errorf("failed to open config: %w", err)
44+
}
45+
defer config.Free()
46+
47+
if err := config.SetString("safe.directory", absWorkspace); err != nil {
48+
return nil, fmt.Errorf("failed to set safe.directory: %w", err)
49+
}
50+
3051
repo, err := git2go.OpenRepository(workspace)
3152
if err != nil {
3253
return nil, fmt.Errorf("failed to open repository at %s: %w", workspace, err)

0 commit comments

Comments
 (0)