From e05c41828c7d70f207d9f1175c6c749646c4c361 Mon Sep 17 00:00:00 2001 From: Nathan Bell Date: Mon, 23 Nov 2020 12:25:44 -0700 Subject: [PATCH] added tests and fixed bug found in tests --- pkg/commands/git_test.go | 74 ++++++++++++++++++++++++++++++++++++---- pkg/commands/sync.go | 4 ++- 2 files changed, 70 insertions(+), 8 deletions(-) diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go index ebac76e01..e65871464 100644 --- a/pkg/commands/git_test.go +++ b/pkg/commands/git_test.go @@ -954,15 +954,23 @@ func TestGitCommandAmendHead(t *testing.T) { // TestGitCommandPush is a function. func TestGitCommandPush(t *testing.T) { type scenario struct { - testName string - command func(string, ...string) *exec.Cmd - forcePush bool - test func(error) + testName string + getLocalGitConfig func(string) (string, error) + getGlobalGitConfig func(string) (string, error) + command func(string, ...string) *exec.Cmd + forcePush bool + test func(error) } scenarios := []scenario{ { - "Push with force disabled", + "Push with force disabled, follow-tags on", + func(string) (string, error) { + return "", nil + }, + func(string) (string, error) { + return "", nil + }, func(cmd string, args ...string) *exec.Cmd { assert.EqualValues(t, "git", cmd) assert.EqualValues(t, []string{"push", "--follow-tags"}, args) @@ -975,7 +983,13 @@ func TestGitCommandPush(t *testing.T) { }, }, { - "Push with force enabled", + "Push with force enabled, follow-tags on", + func(string) (string, error) { + return "", nil + }, + func(string) (string, error) { + return "", nil + }, func(cmd string, args ...string) *exec.Cmd { assert.EqualValues(t, "git", cmd) assert.EqualValues(t, []string{"push", "--follow-tags", "--force-with-lease"}, args) @@ -988,7 +1002,51 @@ func TestGitCommandPush(t *testing.T) { }, }, { - "Push with an error occurring", + "Push with force disabled, follow-tags off locally", + func(string) (string, error) { + return "false", nil + }, + func(string) (string, error) { + return "", nil + }, + func(cmd string, args ...string) *exec.Cmd { + assert.EqualValues(t, "git", cmd) + assert.EqualValues(t, []string{"push"}, args) + + return exec.Command("echo") + }, + false, + func(err error) { + assert.NoError(t, err) + }, + }, + { + "Push with force enabled, follow-tags off globally", + func(string) (string, error) { + return "", nil + }, + func(string) (string, error) { + return "false", nil + }, + func(cmd string, args ...string) *exec.Cmd { + assert.EqualValues(t, "git", cmd) + assert.EqualValues(t, []string{"push", "--force-with-lease"}, args) + + return exec.Command("echo") + }, + true, + func(err error) { + assert.NoError(t, err) + }, + }, + { + "Push with an error occurring, follow-tags on", + func(string) (string, error) { + return "", nil + }, + func(string) (string, error) { + return "", nil + }, func(cmd string, args ...string) *exec.Cmd { assert.EqualValues(t, "git", cmd) assert.EqualValues(t, []string{"push", "--follow-tags"}, args) @@ -1005,6 +1063,8 @@ func TestGitCommandPush(t *testing.T) { t.Run(s.testName, func(t *testing.T) { gitCmd := NewDummyGitCommand() gitCmd.OSCommand.Command = s.command + gitCmd.getLocalGitConfig = s.getLocalGitConfig + gitCmd.getGlobalGitConfig = s.getGlobalGitConfig err := gitCmd.Push("test", s.forcePush, "", "", func(passOrUname string) string { return "\n" }) diff --git a/pkg/commands/sync.go b/pkg/commands/sync.go index 8ebea010b..6f2c6207e 100644 --- a/pkg/commands/sync.go +++ b/pkg/commands/sync.go @@ -26,7 +26,9 @@ func (c *GitCommand) usingGpg() bool { func (c *GitCommand) Push(branchName string, force bool, upstream string, args string, promptUserForCredential func(string) string) error { followTagsFlag := "--follow-tags" followsign, _ := c.getLocalGitConfig("push.followTags") - if followsign == "" { + if followsign == "false" { + followTagsFlag = "" + } else if followsign == "" { followsign, _ = c.getGlobalGitConfig("push.followTags") if followsign == "false" { followTagsFlag = ""