diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2019-11-11 23:22:09 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2019-11-11 23:30:30 +1100 |
commit | 12b84307acd67c93122d1fb971effb9700524592 (patch) | |
tree | 8ba62a274804a85c78898fa11dd2e6797893b9bc /pkg/commands | |
parent | 6843741d9e86bee57c96023a0c66e08cd43b3474 (diff) |
specify upstream when pushing a branch for the first timev0.10.4
Diffstat (limited to 'pkg/commands')
-rw-r--r-- | pkg/commands/git.go | 11 | ||||
-rw-r--r-- | pkg/commands/git_test.go | 8 |
2 files changed, 12 insertions, 7 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go index bd834e574..16b09faa7 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -398,13 +398,18 @@ func (c *GitCommand) Pull(ask func(string) string) error { } // Push pushes to a branch -func (c *GitCommand) Push(branchName string, force bool, ask func(string) string) error { +func (c *GitCommand) Push(branchName string, force bool, upstream string, ask func(string) string) error { forceFlag := "" if force { - forceFlag = "--force-with-lease " + forceFlag = "--force-with-lease" } - cmd := fmt.Sprintf("git push %s-u origin %s", forceFlag, branchName) + setUpstreamArg := "" + if upstream != "" { + setUpstreamArg = "--set-upstream " + upstream + } + + cmd := fmt.Sprintf("git push %s %s", forceFlag, setUpstreamArg) return c.OSCommand.DetectUnamePass(cmd, ask) } diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go index 72328675b..3d5e33998 100644 --- a/pkg/commands/git_test.go +++ b/pkg/commands/git_test.go @@ -990,7 +990,7 @@ func TestGitCommandPush(t *testing.T) { "Push with force disabled", func(cmd string, args ...string) *exec.Cmd { assert.EqualValues(t, "git", cmd) - assert.EqualValues(t, []string{"push", "-u", "origin", "test"}, args) + assert.EqualValues(t, []string{"push"}, args) return exec.Command("echo") }, @@ -1003,7 +1003,7 @@ func TestGitCommandPush(t *testing.T) { "Push with force enabled", func(cmd string, args ...string) *exec.Cmd { assert.EqualValues(t, "git", cmd) - assert.EqualValues(t, []string{"push", "--force-with-lease", "-u", "origin", "test"}, args) + assert.EqualValues(t, []string{"push", "--force-with-lease"}, args) return exec.Command("echo") }, @@ -1016,7 +1016,7 @@ func TestGitCommandPush(t *testing.T) { "Push with an error occurring", func(cmd string, args ...string) *exec.Cmd { assert.EqualValues(t, "git", cmd) - assert.EqualValues(t, []string{"push", "-u", "origin", "test"}, args) + assert.EqualValues(t, []string{"push"}, args) return exec.Command("test") }, false, @@ -1030,7 +1030,7 @@ func TestGitCommandPush(t *testing.T) { t.Run(s.testName, func(t *testing.T) { gitCmd := NewDummyGitCommand() gitCmd.OSCommand.command = s.command - err := gitCmd.Push("test", s.forcePush, func(passOrUname string) string { + err := gitCmd.Push("test", s.forcePush, "", func(passOrUname string) string { return "\n" }) s.test(err) |