Accept raw remote URLs as valid
This commit is contained in:
parent
b546ba4db3
commit
7bd194d25e
@ -228,6 +228,10 @@ func (c *Configuration) GitRemoteUrl(remote string, forpush bool) string {
|
||||
return u
|
||||
}
|
||||
|
||||
if err := git.ValidateRemote(remote); err == nil {
|
||||
return remote
|
||||
}
|
||||
|
||||
return ""
|
||||
|
||||
}
|
||||
|
33
git/git.go
33
git/git.go
@ -8,6 +8,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
@ -233,7 +234,37 @@ func ValidateRemote(remote string) error {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return errors.New("Invalid remote name")
|
||||
|
||||
if err = ValidateRemoteURL(remote); err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("Invalid remote name: %q", remote)
|
||||
}
|
||||
|
||||
// ValidateRemoteURL checks that a string is a valid Git remote URL
|
||||
func ValidateRemoteURL(remote string) error {
|
||||
u, err := url.Parse(remote)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch u.Scheme {
|
||||
case "ssh", "http", "https", "git":
|
||||
return nil
|
||||
case "":
|
||||
// This is either an invalid remote name (maybe the user made a typo
|
||||
// when selecting a named remote) or a bare SSH URL like
|
||||
// "x@y.com:path/to/resource.git". Guess that this is a URL in the latter
|
||||
// form if the string contains a colon ":", and an invalid remote if it
|
||||
// does not.
|
||||
if strings.Contains(remote, ":") {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid remote name: %q", remote)
|
||||
default:
|
||||
return fmt.Errorf("Invalid remote url protocol %q in %q", u.Scheme, remote)
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultRemote returns the default remote based on:
|
||||
|
Loading…
Reference in New Issue
Block a user