Skip to content

Commit e10caf6

Browse files
author
Matthew Fisher
committed
fix(cmd): fix help string when git remote already exists
1 parent 850ee9c commit e10caf6

3 files changed

Lines changed: 65 additions & 6 deletions

File tree

cmd/apps.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (d DeisCmd) AppCreate(id, buildpack, remote string, noRemote bool) error {
5050

5151
if !noRemote {
5252
if err = git.CreateRemote(s.Client.ControllerURL.Host, remote, app.ID); err != nil {
53-
if err.Error() == "exit status 128" {
53+
if strings.Contains(err.Error(), fmt.Sprintf("fatal: remote %s already exists.", remote)) {
5454
msg := "A git remote with the name %s already exists. To overwrite this remote run:\n"
5555
msg += "deis git:remote --force --remote %s --app %s"
5656
return fmt.Errorf(msg, remote, remote, app.ID)

cmd/apps_test.go

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
package cmd
22

3-
import "testing"
3+
import (
4+
"bytes"
5+
"fmt"
6+
"io/ioutil"
7+
"net/http"
8+
"os"
9+
"testing"
10+
11+
"github.com/arschles/assert"
12+
13+
"github.com/deis/workflow-cli/pkg/git"
14+
"github.com/deis/workflow-cli/pkg/testutil"
15+
)
416

517
type expandURLCases struct {
618
Input string
@@ -27,3 +39,42 @@ func TestExpandUrl(t *testing.T) {
2739
}
2840
}
2941
}
42+
43+
func TestRemoteExists(t *testing.T) {
44+
cf, server, err := testutil.NewTestServerAndClient()
45+
if err != nil {
46+
t.Fatal(err)
47+
}
48+
defer server.Close()
49+
50+
server.Mux.HandleFunc("/v2/apps/", func(w http.ResponseWriter, r *http.Request) {
51+
testutil.SetHeaders(w)
52+
fmt.Fprintf(w, `{
53+
"owner": "jkirk",
54+
"id": "foo",
55+
"created": "2014-01-01T00:00:00UTC",
56+
"updated": "2014-01-01T00:00:00UTC",
57+
"uuid": "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75"
58+
}`)
59+
})
60+
61+
// create a remote first before running apps:create
62+
dir, err := ioutil.TempDir("", "apps")
63+
assert.NoErr(t, err)
64+
65+
defer os.RemoveAll(dir)
66+
67+
assert.NoErr(t, os.Chdir(dir))
68+
69+
assert.NoErr(t, git.Init())
70+
assert.NoErr(t, git.CreateRemote("localhost", "deis", "appname"))
71+
72+
var b bytes.Buffer
73+
cmdr := DeisCmd{WOut: &b, ConfigFile: cf}
74+
75+
err = cmdr.AppCreate("foo", "", "deis", false)
76+
77+
assert.Equal(t, err.Error(), `A git remote with the name deis already exists. To overwrite this remote run:
78+
deis git:remote --force --remote deis --app foo`,
79+
"output")
80+
}

pkg/git/git.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,17 @@ func gitError(err *exec.ExitError, cmd []string) error {
2626
// CreateRemote adds a git remote in the current directory.
2727
func CreateRemote(host, remote, appID string) error {
2828
cmd := []string{"git", "remote", "add", remote, RemoteURL(host, appID)}
29-
_, err := exec.Command(cmd[0], cmd[1:]...).Output()
30-
if err != nil {
29+
if _, err := exec.Command(cmd[0], cmd[1:]...).Output(); err != nil {
30+
return gitError(err.(*exec.ExitError), cmd)
31+
}
32+
33+
return nil
34+
}
35+
36+
// Init creates a new git repository in the local directory.
37+
func Init() error {
38+
cmd := []string{"git", "init"}
39+
if _, err := exec.Command(cmd[0], cmd[1:]...).Output(); err != nil {
3140
return gitError(err.(*exec.ExitError), cmd)
3241
}
3342

@@ -54,8 +63,7 @@ func DeleteAppRemotes(host, appID string) error {
5463
// DeleteRemote removes a remote from the repository
5564
func DeleteRemote(name string) error {
5665
cmd := []string{"git", "remote", "remove", name}
57-
_, err := exec.Command(cmd[0], cmd[1:]...).Output()
58-
if err != nil {
66+
if _, err := exec.Command(cmd[0], cmd[1:]...).Output(); err != nil {
5967
return gitError(err.(*exec.ExitError), cmd)
6068
}
6169

0 commit comments

Comments
 (0)