1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-25 12:24:47 +02:00
Jesse Duffield 63dc07fded Construct arg vector manually rather than parse string
By constructing an arg vector manually, we no longer need to quote arguments

Mandate that args must be passed when building a command

Now you need to provide an args array when building a command.
There are a handful of places where we need to deal with a string,
such as with user-defined custom commands, and for those we now require
that at the callsite they use str.ToArgv to do that. I don't want
to provide a method out of the box for it because I want to discourage its
use.

For some reason we were invoking a command through a shell when amending a
commit, and I don't believe we needed to do that as there was nothing user-
supplied about the command. So I've switched to using a regular command out-
side the shell there
2023-05-23 19:49:19 +10:00

105 lines
2.7 KiB
Go

package submodule
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var Reset = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Enter a submodule, create a commit and stage some changes, then reset the submodule from back in the parent repo. This test captures functionality around getting a dirty submodule out of your files panel.",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(cfg *config.AppConfig) {
cfg.UserConfig.CustomCommands = []config.CustomCommand{
{
Key: "e",
Context: "files",
Command: "git commit --allow-empty -m \"empty commit\" && echo \"my_file content\" > my_file",
},
}
},
SetupRepo: func(shell *Shell) {
shell.EmptyCommit("first commit")
shell.CloneIntoSubmodule("my_submodule")
shell.GitAddAll()
shell.Commit("add submodule")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
assertInParentRepo := func() {
t.Views().Status().Content(Contains("repo"))
}
assertInSubmodule := func() {
t.Views().Status().Content(Contains("my_submodule"))
}
assertInParentRepo()
t.Views().Submodules().Focus().
Lines(
Contains("my_submodule").IsSelected(),
).
// enter the submodule
PressEnter()
assertInSubmodule()
t.Views().Status().Content(Contains("my_submodule"))
t.Views().Files().IsFocused().
Press("e").
Tap(func() {
t.Views().Commits().Content(Contains("empty commit"))
t.Views().Files().Content(Contains("my_file"))
}).
Lines(
Contains("my_file").IsSelected(),
).
// stage my_file
PressPrimaryAction().
// return to the parent repo
PressEscape()
assertInParentRepo()
t.Views().Submodules().IsFocused()
t.Views().Main().Content(Contains("Submodule my_submodule contains modified content"))
t.Views().Files().Focus().
Lines(
MatchesRegexp(` M.*my_submodule \(submodule\)`).IsSelected(),
).
Press(keys.Universal.Remove).
Tap(func() {
t.ExpectPopup().Menu().Title(Equals("my_submodule")).Select(Contains("stash uncommitted submodule changes and update")).Confirm()
}).
IsEmpty()
t.Views().Submodules().Focus().
PressEnter()
assertInSubmodule()
// submodule has been hard reset to the commit the parent repo specifies
t.Views().Branches().Lines(
Contains("HEAD detached").IsSelected(),
Contains("master"),
)
// empty commit is gone
t.Views().Commits().Lines(
Contains("first commit").IsSelected(),
)
// the staged change has been stashed
t.Views().Files().IsEmpty()
t.Views().Stash().Focus().
Lines(
Contains("WIP on master").IsSelected(),
)
t.Views().Main().Content(Contains("my_file content"))
},
})