Skip to content

Commit ab7d21a

Browse files
committed
fix: skip the owner validation during parse the git source info
Signed-off-by: chlins <[email protected]>
1 parent 6b5f9c9 commit ab7d21a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

pkg/source/git_libgit2.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,26 @@ package source
2020

2121
import (
2222
"fmt"
23+
"os"
24+
"path/filepath"
2325

2426
git2go "github.com/libgit2/git2go/v34"
2527
)
2628

2729
type git struct{}
2830

2931
func (g *git) Parse(workspace string) (*Info, error) {
30-
repo, err := git2go.OpenRepository(workspace)
32+
absWorkspace, err := filepath.Abs(workspace)
33+
if err != nil {
34+
return nil, fmt.Errorf("failed to get absolute path of workspace: %w", err)
35+
}
36+
// Skip the owner verification as we only need to retrieve some metadata,
37+
// set the environment variable to configure it because don't found direct function or option in git2go.
38+
os.Setenv("GIT_CONFIG_COUNT", "1")
39+
os.Setenv("GIT_CONFIG_KEY_0", "safe.directory")
40+
os.Setenv("GIT_CONFIG_VALUE_0", absWorkspace)
41+
42+
repo, err := git2go.OpenRepositoryExtended(workspace, git2go.RepositoryOpenFromEnv, "")
3143
if err != nil {
3244
return nil, fmt.Errorf("failed to open repository at %s: %w", workspace, err)
3345
}

0 commit comments

Comments
 (0)