in scan/git.go [198:237]
func parseRemoteURL(remoteURL string) (gitRepo, error) {
repo := gitRepo{}
if !isGitTransport(remoteURL) {
remoteURL = "https://" + remoteURL
}
var fragment string
if strings.HasPrefix(remoteURL, "git@") {
// git@.. is not an URL, so cannot be parsed as URL
parts := strings.SplitN(remoteURL, "#", 2)
repo.remote = parts[0]
if len(parts) == 2 {
fragment = parts[1]
}
repo.ref, repo.subdir = getRefAndSubdir(fragment)
} else {
u, err := url.Parse(remoteURL)
if err != nil {
return repo, err
}
repo.ref, repo.subdir = getRefAndSubdir(u.Fragment)
u.Fragment = ""
if userName := u.User.Username(); userName != "" {
if _, passwordSet := u.User.Password(); !passwordSet {
// For private git repositories, GitHub and Azure DevOps support git urls like http://pat@gitbhub.com/user/repo.git
// However git-lfs requires the credential in "user:pat" format. So we need to add a dummy user name.
// Other git services like GitLab, BitBucket only support "user:pat" credential.
// NOTE: If the git repository is public, the user section in git url doesn't matter.
pat := userName
u.User = url.UserPassword("dummy", pat)
}
}
repo.remote = u.String()
}
return repo, nil
}