mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Move IsGitTransport() to gitutils
This function was only used inside gitutils, and is written specifically for the requirements there. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
913eb99fdc
commit
d3d1aabcc6
4 changed files with 34 additions and 21 deletions
|
@ -57,7 +57,7 @@ func Clone(remoteURL string) (string, error) {
|
||||||
func parseRemoteURL(remoteURL string) (gitRepo, error) {
|
func parseRemoteURL(remoteURL string) (gitRepo, error) {
|
||||||
repo := gitRepo{}
|
repo := gitRepo{}
|
||||||
|
|
||||||
if !urlutil.IsGitTransport(remoteURL) {
|
if !isGitTransport(remoteURL) {
|
||||||
remoteURL = "https://" + remoteURL
|
remoteURL = "https://" + remoteURL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,3 +151,9 @@ func gitWithinDir(dir string, args ...string) ([]byte, error) {
|
||||||
func git(args ...string) ([]byte, error) {
|
func git(args ...string) ([]byte, error) {
|
||||||
return exec.Command("git", args...).CombinedOutput()
|
return exec.Command("git", args...).CombinedOutput()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 urlutil.IsURL(str) || strings.HasPrefix(str, "git://") || strings.HasPrefix(str, "git@")
|
||||||
|
}
|
||||||
|
|
|
@ -209,3 +209,30 @@ func TestCheckoutGit(t *testing.T) {
|
||||||
assert.Equal(t, c.exp, string(b))
|
assert.Equal(t, c.exp, string(b))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestValidGitTransport(t *testing.T) {
|
||||||
|
gitUrls := []string{
|
||||||
|
"git://github.com/docker/docker",
|
||||||
|
"git@github.com:docker/docker.git",
|
||||||
|
"git@bitbucket.org:atlassianlabs/atlassian-docker.git",
|
||||||
|
"https://github.com/docker/docker.git",
|
||||||
|
"http://github.com/docker/docker.git",
|
||||||
|
"http://github.com/docker/docker.git#branch",
|
||||||
|
"http://github.com/docker/docker.git#:dir",
|
||||||
|
}
|
||||||
|
incompleteGitUrls := []string{
|
||||||
|
"github.com/docker/docker",
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, url := range gitUrls {
|
||||||
|
if !isGitTransport(url) {
|
||||||
|
t.Fatalf("%q should be detected as valid Git prefix", url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, url := range incompleteGitUrls {
|
||||||
|
if isGitTransport(url) {
|
||||||
|
t.Fatalf("%q should not be detected as valid Git prefix", url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -29,12 +29,6 @@ func IsGitURL(str string) bool {
|
||||||
return checkURL(str, "git")
|
return checkURL(str, "git")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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@")
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsTransportURL returns true if the provided str is a transport (tcp, tcp+tls, udp, unix) URL.
|
// IsTransportURL returns true if the provided str is a transport (tcp, tcp+tls, udp, unix) URL.
|
||||||
func IsTransportURL(str string) bool {
|
func IsTransportURL(str string) bool {
|
||||||
return checkURL(str, "transport")
|
return checkURL(str, "transport")
|
||||||
|
|
|
@ -27,20 +27,6 @@ var (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestValidGitTransport(t *testing.T) {
|
|
||||||
for _, url := range gitUrls {
|
|
||||||
if !IsGitTransport(url) {
|
|
||||||
t.Fatalf("%q should be detected as valid Git prefix", url)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, url := range incompleteGitUrls {
|
|
||||||
if IsGitTransport(url) {
|
|
||||||
t.Fatalf("%q should not be detected as valid Git prefix", url)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestIsGIT(t *testing.T) {
|
func TestIsGIT(t *testing.T) {
|
||||||
for _, url := range gitUrls {
|
for _, url := range gitUrls {
|
||||||
if !IsGitURL(url) {
|
if !IsGitURL(url) {
|
||||||
|
|
Loading…
Reference in a new issue