add support for alternate remotes by grabbing it out of the git hawser push args

This commit is contained in:
Rick Olson 2015-02-02 15:39:03 -07:00
parent 4367c72822
commit df17f104c1
3 changed files with 46 additions and 6 deletions

@ -62,6 +62,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,15 +12,17 @@ import (
)
type Configuration struct {
CurrentRemote string
gitConfig map[string]string
remotes []string
httpClient *http.Client
}
var (
Config = &Configuration{}
httpPrefixRe = regexp.MustCompile("\\Ahttps?://")
Config = &Configuration{CurrentRemote: defaultRemote}
RedirectError = fmt.Errorf("Unexpected redirection")
httpPrefixRe = regexp.MustCompile("\\Ahttps?://")
defaultRemote = "origin"
)
func HttpClient() *http.Client {
@ -47,10 +49,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"},