merge master
This commit is contained in:
commit
7252be8315
@ -61,6 +61,8 @@ func pushCommand(cmd *cobra.Command, args []string) {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
hawser.Config.CurrentRemote = args[0]
|
||||
|
||||
if useStdin {
|
||||
refsData, err := ioutil.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
)
|
||||
|
||||
type Configuration struct {
|
||||
CurrentRemote string
|
||||
gitConfig map[string]string
|
||||
remotes []string
|
||||
httpClient *http.Client
|
||||
@ -19,9 +20,10 @@ type Configuration struct {
|
||||
}
|
||||
|
||||
var (
|
||||
Config = &Configuration{}
|
||||
httpPrefixRe = regexp.MustCompile("\\Ahttps?://")
|
||||
Config = &Configuration{CurrentRemote: defaultRemote}
|
||||
RedirectError = fmt.Errorf("Unexpected redirection")
|
||||
httpPrefixRe = regexp.MustCompile("\\Ahttps?://")
|
||||
defaultRemote = "origin"
|
||||
)
|
||||
|
||||
func (c *Configuration) Endpoint() string {
|
||||
@ -29,10 +31,20 @@ func (c *Configuration) Endpoint() string {
|
||||
return url
|
||||
}
|
||||
|
||||
return c.RemoteEndpoint("origin")
|
||||
if len(c.CurrentRemote) > 0 && c.CurrentRemote != defaultRemote {
|
||||
if endpoint := c.RemoteEndpoint(c.CurrentRemote); len(endpoint) > 0 {
|
||||
return endpoint
|
||||
}
|
||||
}
|
||||
|
||||
return c.RemoteEndpoint(defaultRemote)
|
||||
}
|
||||
|
||||
func (c *Configuration) RemoteEndpoint(remote string) string {
|
||||
if len(remote) == 0 {
|
||||
remote = defaultRemote
|
||||
}
|
||||
|
||||
if url, ok := c.GitConfig("remote." + remote + ".hawser"); ok {
|
||||
return url
|
||||
}
|
||||
|
@ -26,6 +26,32 @@ func TestEndpointOverridesOrigin(t *testing.T) {
|
||||
assert.Equal(t, "abc", config.Endpoint())
|
||||
}
|
||||
|
||||
func TestEndpointNoOverrideDefaultRemote(t *testing.T) {
|
||||
config := &Configuration{
|
||||
gitConfig: map[string]string{
|
||||
"remote.origin.hawser": "abc",
|
||||
"remote.other.hawser": "def",
|
||||
},
|
||||
remotes: []string{},
|
||||
}
|
||||
|
||||
assert.Equal(t, "abc", config.Endpoint())
|
||||
}
|
||||
|
||||
func TestEndpointUseAlternateRemote(t *testing.T) {
|
||||
config := &Configuration{
|
||||
gitConfig: map[string]string{
|
||||
"remote.origin.hawser": "abc",
|
||||
"remote.other.hawser": "def",
|
||||
},
|
||||
remotes: []string{},
|
||||
}
|
||||
|
||||
config.CurrentRemote = "other"
|
||||
|
||||
assert.Equal(t, "def", config.Endpoint())
|
||||
}
|
||||
|
||||
func TestEndpointAddsMediaSuffix(t *testing.T) {
|
||||
config := &Configuration{
|
||||
gitConfig: map[string]string{"remote.origin.url": "https://example.com/foo/bar"},
|
||||
|
Loading…
Reference in New Issue
Block a user