(fix) Git Repo Cloning Error (#4223)

* instead of providing list of refs we want to scan, using --mirror parameter .
removed SkipAdditionalRefs flag, cloning using --mirror will include all the refs.
put the check if userinfo is nil to avoid any crash due to invalid memory access.

* keep both -c and --mirror

* keep useGitMirror on by default for OSS

---------

Co-authored-by: Shahzad Haider <[email protected]>
Co-authored-by: Dustin Decker <[email protected]>
Co-authored-by: ahrav <[email protected]>
This commit is contained in:
Abdul Basit
2025-07-25 10:30:30 -07:00
committed by GitHub
co-authored by Shahzad Haider Dustin Decker ahrav
parent 29ad3e7a3f
commit ad1ddc133a
3 changed files with 21 additions and 6 deletions
+4
View File
@@ -450,6 +450,10 @@ func run(state overseer.State) {
// OSS Default APK handling on
feature.EnableAPKHandler.Store(true)
// OSS Default Use Git Mirror on
feature.UseGitMirror.Store(true)
// OSS Default simplified gitlab enumeration
feature.UseSimplifiedGitlabEnumeration.Store(true)
+1
View File
@@ -9,6 +9,7 @@ var (
EnableAPKHandler atomic.Bool
UserAgentSuffix AtomicString
UseSimplifiedGitlabEnumeration atomic.Bool
UseGitMirror atomic.Bool
)
type AtomicString struct {
+16 -6
View File
@@ -445,16 +445,26 @@ func executeClone(ctx context.Context, params cloneParams) (*git.Repository, err
gitArgs = append(gitArgs, "-c", fmt.Sprintf("http.extraHeader=Authorization: Basic %s", authHeader))
}
}
if !feature.SkipAdditionalRefs.Load() {
// append clone argument
gitArgs = append(gitArgs, "clone")
var dstGitDir string
if feature.UseGitMirror.Load() {
gitArgs = append(gitArgs,
"-c",
"remote.origin.fetch=+refs/*:refs/remotes/origin/*")
"--mirror",
)
dstGitDir = filepath.Join(params.clonePath, gitDirName) // <tmp>/.git
} else {
if !feature.SkipAdditionalRefs.Load() {
gitArgs = append(gitArgs,
"-c",
"remote.origin.fetch=+refs/*:refs/remotes/origin/*")
}
dstGitDir = params.clonePath
}
gitArgs = append(gitArgs, "clone",
gitArgs = append(gitArgs,
cloneURL.String(),
params.clonePath,
dstGitDir,
"--quiet", // https://git-scm.com/docs/git-clone#Documentation/git-clone.txt-code--quietcode
)