mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-01-26 05:37:18 +02:00
added tests and fixed bug found in tests
This commit is contained in:
parent
c4cce58464
commit
e05c41828c
@ -954,15 +954,23 @@ func TestGitCommandAmendHead(t *testing.T) {
|
|||||||
// TestGitCommandPush is a function.
|
// TestGitCommandPush is a function.
|
||||||
func TestGitCommandPush(t *testing.T) {
|
func TestGitCommandPush(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
command func(string, ...string) *exec.Cmd
|
getLocalGitConfig func(string) (string, error)
|
||||||
forcePush bool
|
getGlobalGitConfig func(string) (string, error)
|
||||||
test func(error)
|
command func(string, ...string) *exec.Cmd
|
||||||
|
forcePush bool
|
||||||
|
test func(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
scenarios := []scenario{
|
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 {
|
func(cmd string, args ...string) *exec.Cmd {
|
||||||
assert.EqualValues(t, "git", cmd)
|
assert.EqualValues(t, "git", cmd)
|
||||||
assert.EqualValues(t, []string{"push", "--follow-tags"}, args)
|
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 {
|
func(cmd string, args ...string) *exec.Cmd {
|
||||||
assert.EqualValues(t, "git", cmd)
|
assert.EqualValues(t, "git", cmd)
|
||||||
assert.EqualValues(t, []string{"push", "--follow-tags", "--force-with-lease"}, args)
|
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 {
|
func(cmd string, args ...string) *exec.Cmd {
|
||||||
assert.EqualValues(t, "git", cmd)
|
assert.EqualValues(t, "git", cmd)
|
||||||
assert.EqualValues(t, []string{"push", "--follow-tags"}, args)
|
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) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
gitCmd := NewDummyGitCommand()
|
gitCmd := NewDummyGitCommand()
|
||||||
gitCmd.OSCommand.Command = s.command
|
gitCmd.OSCommand.Command = s.command
|
||||||
|
gitCmd.getLocalGitConfig = s.getLocalGitConfig
|
||||||
|
gitCmd.getGlobalGitConfig = s.getGlobalGitConfig
|
||||||
err := gitCmd.Push("test", s.forcePush, "", "", func(passOrUname string) string {
|
err := gitCmd.Push("test", s.forcePush, "", "", func(passOrUname string) string {
|
||||||
return "\n"
|
return "\n"
|
||||||
})
|
})
|
||||||
|
@ -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 {
|
func (c *GitCommand) Push(branchName string, force bool, upstream string, args string, promptUserForCredential func(string) string) error {
|
||||||
followTagsFlag := "--follow-tags"
|
followTagsFlag := "--follow-tags"
|
||||||
followsign, _ := c.getLocalGitConfig("push.followTags")
|
followsign, _ := c.getLocalGitConfig("push.followTags")
|
||||||
if followsign == "" {
|
if followsign == "false" {
|
||||||
|
followTagsFlag = ""
|
||||||
|
} else if followsign == "" {
|
||||||
followsign, _ = c.getGlobalGitConfig("push.followTags")
|
followsign, _ = c.getGlobalGitConfig("push.followTags")
|
||||||
if followsign == "false" {
|
if followsign == "false" {
|
||||||
followTagsFlag = ""
|
followTagsFlag = ""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user