mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
49fd83a25e
Signed-off-by: David Calavera <david.calavera@gmail.com>
35 lines
769 B
Go
35 lines
769 B
Go
package urlutil
|
|
|
|
import (
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
var (
|
|
validPrefixes = []string{
|
|
"git://",
|
|
"github.com/",
|
|
"git@",
|
|
}
|
|
|
|
urlPathWithFragmentSuffix = regexp.MustCompile(".git(?:#.+)?$")
|
|
)
|
|
|
|
// IsGitURL returns true if the provided str is a git repository URL.
|
|
func IsGitURL(str string) bool {
|
|
if IsURL(str) && urlPathWithFragmentSuffix.MatchString(str) {
|
|
return true
|
|
}
|
|
for _, prefix := range validPrefixes {
|
|
if strings.HasPrefix(str, prefix) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// IsGitTransport returns true if the provided str is a git transport by inspecting
|
|
// the prefix of the string for known protocols used in git.
|
|
func IsGitTransport(str string) bool {
|
|
return IsURL(str) || strings.HasPrefix(str, "git://") || strings.HasPrefix(str, "git@")
|
|
}
|