mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-10 23:57:43 +02:00
commands/git : add test to Checkout, refactor
This commit is contained in:
parent
67a42f49b4
commit
b641d6bd96
@ -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
|
||||||
|
@ -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"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user