1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-08 23:56:15 +02:00

commands/git : add test to Checkout, refactor

This commit is contained in:
Anthony HAMON 2018-09-16 22:08:23 +02:00
parent 67a42f49b4
commit b641d6bd96
2 changed files with 47 additions and 1 deletions

View File

@ -428,7 +428,7 @@ func (c *GitCommand) Checkout(branch string, force bool) error {
if force { if force {
forceArg = "--force " forceArg = "--force "
} }
return c.OSCommand.RunCommand("git checkout " + forceArg + branch) return c.OSCommand.RunCommand(fmt.Sprintf("git checkout %s %s", forceArg, branch))
} }
// AddPatch prepares a subprocess for adding a patch by patch // AddPatch prepares a subprocess for adding a patch by patch

View File

@ -1421,6 +1421,52 @@ func TestGitCommandRemoveFile(t *testing.T) {
} }
} }
func TestGitCommandCheckout(t *testing.T) {
type scenario struct {
testName string
command func(string, ...string) *exec.Cmd
test func(error)
force bool
}
scenarios := []scenario{
{
"Checkout",
func(cmd string, args ...string) *exec.Cmd {
assert.EqualValues(t, "git", cmd)
assert.EqualValues(t, []string{"checkout", "test"}, args)
return exec.Command("echo")
},
func(err error) {
assert.NoError(t, err)
},
false,
},
{
"Checkout forced",
func(cmd string, args ...string) *exec.Cmd {
assert.EqualValues(t, "git", cmd)
assert.EqualValues(t, []string{"checkout", "--force", "test"}, args)
return exec.Command("echo")
},
func(err error) {
assert.NoError(t, err)
},
true,
},
}
for _, s := range scenarios {
t.Run(s.testName, func(t *testing.T) {
gitCmd := newDummyGitCommand()
gitCmd.OSCommand.command = s.command
s.test(gitCmd.Checkout("test", s.force))
})
}
}
func TestGitCommandDiff(t *testing.T) { func TestGitCommandDiff(t *testing.T) {
gitCommand := newDummyGitCommand() gitCommand := newDummyGitCommand()
assert.NoError(t, test.GenerateRepo("lots_of_diffs.sh")) assert.NoError(t, test.GenerateRepo("lots_of_diffs.sh"))