summaryrefslogtreecommitdiffstats
path: root/pkg/integration
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-02-20 21:52:27 +1100
committerJesse Duffield <jessedduffield@gmail.com>2023-02-20 21:52:27 +1100
commit2b6a109e3838e39eec8314f4ff50e6e3068c0c21 (patch)
tree37ec455b53540aad1b8c1222bb2d63d8269f8387 /pkg/integration
parente1c376ef5490f3e964ee8c5bd554957c05c60884 (diff)
migrate stash tests
Diffstat (limited to 'pkg/integration')
-rw-r--r--pkg/integration/components/shell.go6
-rw-r--r--pkg/integration/tests/stash/apply.go43
-rw-r--r--pkg/integration/tests/stash/apply_patch.go53
-rw-r--r--pkg/integration/tests/stash/create_branch.go54
-rw-r--r--pkg/integration/tests/stash/drop.go38
-rw-r--r--pkg/integration/tests/stash/pop.go41
-rw-r--r--pkg/integration/tests/stash/stash.go6
-rw-r--r--pkg/integration/tests/stash/stash_all.go40
-rw-r--r--pkg/integration/tests/stash/stash_and_keep_index.go56
-rw-r--r--pkg/integration/tests/stash/stash_staged.go55
-rw-r--r--pkg/integration/tests/stash/stash_unstaged.go55
-rw-r--r--pkg/integration/tests/tests_gen.go9
12 files changed, 452 insertions, 4 deletions
diff --git a/pkg/integration/components/shell.go b/pkg/integration/components/shell.go
index ad6d195f5..bacd23a45 100644
--- a/pkg/integration/components/shell.go
+++ b/pkg/integration/components/shell.go
@@ -207,3 +207,9 @@ func (self *Shell) HardReset(ref string) *Shell {
return self
}
+
+func (self *Shell) Stash(message string) *Shell {
+ self.RunCommand(fmt.Sprintf("git stash -m \"%s\"", message))
+
+ return self
+}
diff --git a/pkg/integration/tests/stash/apply.go b/pkg/integration/tests/stash/apply.go
new file mode 100644
index 000000000..dfaa5130a
--- /dev/null
+++ b/pkg/integration/tests/stash/apply.go
@@ -0,0 +1,43 @@
+package stash
+
+import (
+ "github.com/jesseduffield/lazygit/pkg/config"
+ . "github.com/jesseduffield/lazygit/pkg/integration/components"
+)
+
+var Apply = NewIntegrationTest(NewIntegrationTestArgs{
+ Description: "Apply a stash entry",
+ ExtraCmdArgs: "",
+ Skip: false,
+ SetupConfig: func(config *config.AppConfig) {},
+ SetupRepo: func(shell *Shell) {
+ shell.EmptyCommit("initial commit")
+ shell.CreateFile("file", "content")
+ shell.GitAddAll()
+ shell.Stash("stash one")
+ },
+ Run: func(t *TestDriver, keys config.KeybindingConfig) {
+ t.Views().Files().IsEmpty()
+
+ t.Views().Stash().
+ Focus().
+ Lines(
+ Contains("stash one").IsSelected(),
+ ).
+ PressPrimaryAction().
+ Tap(func() {
+ t.ExpectPopup().Confirmation().
+ Title(Equals("Stash apply")).
+ Content(Contains("Are you sure you want to apply this stash entry?")).
+ Confirm()
+ }).
+ Lines(
+ Contains("stash one").IsSelected(),
+ )
+
+ t.Views().Files().
+ Lines(
+ Contains("file"),
+ )
+ },
+})
diff --git a/pkg/integration/tests/stash/apply_patch.go b/pkg/integration/tests/stash/apply_patch.go
new file mode 100644
index 000000000..f8bf498ba
--- /dev/null
+++ b/pkg/integration/tests/stash/apply_patch.go
@@ -0,0 +1,53 @@
+package stash
+
+import (
+ "github.com/jesseduffield/lazygit/pkg/config"
+ . "github.com/jesseduffield/lazygit/pkg/integration/components"
+)
+
+var ApplyPatch = NewIntegrationTest(NewIntegrationTestArgs{
+ Description: "Restore part of a stash entry via applying a custom patch",
+ ExtraCmdArgs: "",
+ Skip: false,
+ SetupConfig: func(config *config.AppConfig) {},
+ SetupRepo: func(shell *Shell) {
+ shell.EmptyCommit("initial commit")
+ shell.CreateFile("myfile", "content")
+ shell.CreateFile("myfile2", "content")
+ shell.GitAddAll()
+ shell.Stash("stash one")
+ },
+ Run: func(t *TestDriver, keys config.KeybindingConfig) {
+ t.Views().Files().IsEmpty()
+
+ t.Views().Stash().
+ Focus().
+ Lines(
+ Contains("stash one").IsSelected(),
+ ).
+ PressEnter().
+ Tap(func() {
+ t.Views().CommitFiles().
+ IsFocused().
+ Lines(
+ Contains("myfile").IsSelected(),
+ Contains("myfile2"),
+ ).
+ PressPrimaryAction()
+
+ t.Views().Information().Content(Contains("building patch"))
+
+ t.Views().
+ CommitFiles().
+ Press(keys.Universal.CreatePatchOptionsMenu)
+
+ t.ExpectPopup().Menu().
+ Title(Equals("Patch Options")).
+ Select(MatchesRegexp(`apply patch$`)).Confirm()
+ })
+
+ t.Views().Files().Lines(
+ Contains("myfile"),
+ )
+ },
+})
diff --git a/pkg/integration/tests/stash/create_branch.go b/pkg/integration/tests/stash/create_branch.go
new file mode 100644
index 000000000..e6ea9c40c
--- /dev/null
+++ b/pkg/integration/tests/stash/create_branch.go
@@ -0,0 +1,54 @@
+package stash
+
+import (
+ "github.com/jesseduffield/lazygit/pkg/config"
+ . "github.com/jesseduffield/lazygit/pkg/integration/components"
+)
+
+var CreateBranch = NewIntegrationTest(NewIntegrationTestArgs{
+ Description: "Create a branch from a stash entry",
+ ExtraCmdArgs: "",
+ Skip: false,
+ SetupConfig: func(config *config.AppConfig) {},
+ SetupRepo: func(shell *Shell) {
+ shell.EmptyCommit("initial commit")
+ shell.CreateFile("myfile", "content")
+ shell.GitAddAll()
+ shell.Stash("stash one")
+ },
+ Run: func(t *TestDriver, keys config.KeybindingConfig) {
+ t.Views().Files().IsEmpty()
+
+ t.Views().Stash().
+ Focus().
+ Lines(
+ Contains("stash one").IsSelected(),
+ ).
+ Press(keys.Universal.New).
+ Tap(func() {
+ t.ExpectPopup().Prompt().
+ Title(Contains("New Branch Name (Branch is off of 'stash@{0}: On master: stash one'")).
+ Type("new_branch").
+ Confirm()
+ })
+
+ t.Views().Files().IsEmpty()
+
+ t.Views().Branches().
+ IsFocused().
+ Lines(
+ Contains("new_branch").IsSelected(),
+ Contains("master"),
+ ).
+ PressEnter()
+
+ t.Views().SubCommits().
+ Lines(
+ Contains("On master: stash one").IsSelected(),
+ MatchesRegexp(`index on master:.*initial commit`),
+ Contains("initial commit"),
+ )
+
+ t.Views().Main().Content(Contains("myfile | 1 +"))
+ },
+})
diff --git a/pkg/integration/tests/stash/drop.go b/pkg/integration/tests/stash/drop.go
new file mode 100644
index 000000000..1450cfa30
--- /dev/null
+++ b/pkg/integration/tests/stash/drop.go
@@ -0,0 +1,38 @@
+package stash
+
+import (
+ "github.com/jesseduffield/lazygit/pkg/config"
+ . "github.com/jesseduffield/lazygit/pkg/integration/components"
+)
+
+var Drop = NewIntegrationTest(NewIntegrationTestArgs{
+ Description: "Drop a stash entry",
+ ExtraCmdArgs: "",
+ Skip: false,
+ SetupConfig: func(config *config.AppConfig) {},
+ SetupRepo: func(shell *Shell) {
+ shell.EmptyCommit("initial commit")
+ shell.CreateFile("file", "content")
+ shell.GitAddAll()
+ shell.Stash("stash one")
+ },
+ Run: func(t *TestDriver, keys config.KeybindingConfig) {
+ t.Views().Files().IsEmpty()
+
+ t.Views().Stash().
+ Focus().
+ Lines(
+ Contains("stash one").IsSelected(),
+ ).
+ Press(keys.Universal.Remove).
+ Tap(func() {
+ t.ExpectPopup().Confirmation().
+ Title(Equals("Stash drop")).
+ Content(Contains("Are you sure you want to drop this stash entry?")).
+ Confirm()
+ }).
+ IsEmpty()
+
+ t.Views().Files().IsEmpty()
+ },
+})
diff --git a/pkg/integration/tests/stash/pop.go b/pkg/integration/tests/stash/pop.go
new file mode 100644
index 000000000..369e3e50d
--- /dev/null
+++ b/pkg/integration/tests/stash/pop.go
@@ -0,0 +1,41 @@
+package stash
+
+import (
+ "github.com/jesseduffield/lazygit/pkg/config"
+ . "github.com/jesseduffield/lazygit/pkg/integration/components"
+)
+
+var Pop = NewIntegrationTest(NewIntegrationTestArgs{
+ Description: "Pop a stash entry",
+ ExtraCmdArgs: "",
+ Skip: false,
+ SetupConfig: func(config *config.AppConfig) {},
+ SetupRepo: func(shell *Shell) {
+ shell.EmptyCommit("initial commit")
+ shell.CreateFile("file", "content")
+ shell.GitAddAll()
+ shell.Stash("stash one")
+ },
+ Run: func(t *TestDriver, keys config.KeybindingConfig) {
+ t.Views().Files().IsEmpty()
+
+ t.Views().Stash().
+ Focus().
+ Lines(
+ Contains("stash one").IsSelected(),
+ ).
+ Press(keys.Stash.PopStash).
+ Tap(func() {
+ t.ExpectPopup().Confirmation().
+ Title(Equals("Stash pop")).
+ Content(Contains("Are you sure you want to pop this stash entry?")).
+ Confirm()
+ }).
+ IsEmpty()
+
+ t.Views().Files().
+ Lines(
+ Contains("file"),
+ )
+ },
+})
diff --git a/pkg/integration/tests/stash/stash.go b/pkg/integration/tests/stash/stash.go
index f88aac2d0..aa2393cd8 100644
--- a/pkg/integration/tests/stash/stash.go
+++ b/pkg/integration/tests/stash/stash.go
@@ -6,7 +6,7 @@ import (
)
var Stash = NewIntegrationTest(NewIntegrationTestArgs{
- Description: "Stashing files",
+ Description: "Stashing files directly (not going through the stash menu)",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
@@ -23,9 +23,7 @@ var Stash = NewIntegrationTest(NewIntegrationTestArgs{
Lines(
Contains("file"),
).
- Press(keys.Files.ViewStashOptions)
-
- t.ExpectPopup().Menu().Title(Equals("Stash options")).Select(MatchesRegexp("stash all changes$")).Confirm()
+ Press(keys.Files.StashAllChanges)
t.ExpectPopup().Prompt().Title(Equals("Stash changes")).Type("my stashed file").Confirm()
diff --git a/pkg/integration/tests/stash/stash_all.go b/pkg/integration/tests/stash/stash_all.go
new file mode 100644
index 000000000..494617d02
--- /dev/null
+++ b/pkg/integration/tests/stash/stash_all.go
@@ -0,0 +1,40 @@
+package stash
+
+import (
+ "github.com/jesseduffield/lazygit/pkg/config"
+ . "github.com/jesseduffield/lazygit/pkg/integration/components"
+)
+
+var StashAll = NewIntegrationTest(NewIntegrationTestArgs{
+ Description: "Stashing all changes (via the menu)",
+ ExtraCmdArgs: "",
+ Skip: false,
+ SetupConfig: func(config *config.AppConfig) {},
+ SetupRepo: func(shell *Shell) {
+ shell.EmptyCommit("initial commit")
+ shell.CreateFile("file", "content")
+ shell.GitAddAll()
+ },
+ Run: func(t *TestDriver, keys config.KeybindingConfig) {
+ t.Views().Stash().
+ IsEmpty()
+
+ t.Views().Files().
+ Lines(
+ Contains("file"),
+ ).
+ Press(keys.Files.ViewStashOptions)
+
+ t.ExpectPopup().Menu().Title(Equals("Stash options")).Select(MatchesRegexp("stash all changes$")).Confirm()
+
+ t.ExpectPopup().Prompt().Title(Equals("Stash changes")).Type("my stashed file").Confirm()
+
+ t.Views().Stash().
+ Lines(
+ Contains("my stashed file"),
+ )
+
+ t.Views().Files().
+ IsEmpty()
+ },
+})
diff --git a/pkg/integration/tests/stash/stash_and_keep_index.go b/pkg/integration/tests/stash/stash_and_keep_index.go
new file mode 100644
index 000000000..1f1e91152
--- /dev/null
+++ b/pkg/integration/tests/stash/stash_and_keep_index.go
@@ -0,0 +1,56 @@
+package stash
+
+import (
+ "github.com/jesseduffield/lazygit/pkg/config"
+ . "github.com/jesseduffield/lazygit/pkg/integration/components"
+)
+
+var StashAndKeepIndex = NewIntegrationTest(NewIntegrationTestArgs{
+ Description: "Stash staged changes",
+ ExtraCmdArgs: "",
+ Skip: false,
+ SetupConfig: func(config *config.AppConfig) {},
+ SetupRepo: func(shell *Shell) {
+ shell.CreateFileAndAdd("file-staged", "content")
+ shell.CreateFileAndAdd("file-unstaged", "content")
+ shell.EmptyCommit("initial commit")
+ shell.UpdateFileAndAdd("file-staged", "new content")
+ shell.UpdateFile("file-unstaged", "new content")
+ },
+ Run: func(t *TestDriver, keys config.KeybindingConfig) {
+ t.Views().Stash().
+ IsEmpty()
+
+ t.Views().Files().
+ Lines(
+ Contains("file-staged"),
+ Contains("file-unstaged"),
+ ).
+ Press(keys.Files.ViewStashOptions)
+
+ t.ExpectPopup().Menu().Title(Equals("Stash options")).Select(Contains("stash all changes and keep index")).Confirm()
+
+ t.ExpectPopup().Prompt().Title(Equals("Stash changes")).Type("my stashed file").Confirm()
+
+ t.Views().Stash().
+ Lines(
+ Contains("my stashed file"),
+ )
+
+ t.Views().Files().
+ Lines(
+ Contains("file-staged"),
+ )
+
+ t.Views().Stash().
+ Focus().
+ PressEnter()
+
+ t.Views().CommitFiles().
+ IsFocused().
+ Lines(
+ Contains("file-staged"),
+ Contains("file-unstaged"),
+ )
+ },
+})
diff --git a/pkg/integration/tests/stash/stash_staged.go b/pkg/integration/tests/stash/stash_staged.go
new file mode 100644
index 000000000..2fcd86c68
--- /dev/null
+++ b/pkg/integration/tests/stash/stash_staged.go
@@ -0,0 +1,55 @@
+package stash
+
+import (
+ "github.com/jesseduffield/lazygit/pkg/config"
+ . "github.com/jesseduffield/lazygit/pkg/integration/components"
+)
+
+var StashStaged = NewIntegrationTest(NewIntegrationTestArgs{
+ Description: "Stash staged changes",
+ ExtraCmdArgs: "",
+ Skip: false,
+ SetupConfig: func(config *config.AppConfig) {},
+ SetupRepo: func(shell *Shell) {
+ shell.CreateFileAndAdd("file-staged", "content")
+ shell.CreateFileAndAdd("file-unstaged", "content")
+ shell.EmptyCommit("initial commit")
+ shell.UpdateFileAndAdd("file-staged", "new content")
+ shell.UpdateFile("file-unstaged", "new content")
+ },
+ Run: func(t *TestDriver, keys config.KeybindingConfig) {
+ t.Views().Stash().
+ IsEmpty()
+
+ t.Views().Files().
+ Lines(
+ Contains("file-staged"),
+ Contains("file-unstaged"),
+ ).
+ Press(keys.Files.ViewStashOptions)
+
+ t.ExpectPopup().Menu().Title(Equals("Stash options")).Select(MatchesRegexp("stash staged changes$")).Confirm()
+
+ t.ExpectPopup().Prompt().Title(Equals("Stash changes")).Type("my stashed file").Confirm()
+
+ t.Views().Stash().
+ Lines(
+ Contains("my stashed file"),
+ )
+
+ t.Views().Files().
+ Lines(
+ Contains("file-unstaged"),
+ )
+
+ t.Views().Stash().
+ Focus().
+ PressEnter()
+
+ t.Views().CommitFiles().
+ IsFocused().
+ Lines(
+ Contains("file-staged").IsSelected(),
+ )
+ },
+})
diff --git a/pkg/integration/tests/stash/stash_unstaged.go b/pkg/integration/tests/stash/stash_unstaged.go
new file mode 100644
index 000000000..6e8877681
--- /dev/null
+++ b/pkg/integration/tests/stash/stash_unstaged.go
@@ -0,0 +1,55 @@
+package stash
+
+import (
+ "github.com/jesseduffield/lazygit/pkg/config"
+ . "github.com/jesseduffield/lazygit/pkg/integration/components"
+)
+
+var StashUnstaged = NewIntegrationTest(NewIntegrationTestArgs{
+ Description: "Stash unstaged changes",
+ ExtraCmdArgs: "",
+ Skip: false,
+ SetupConfig: func(config *config.AppConfig) {},
+ SetupRepo: func(shell *Shell) {
+ shell.CreateFileAndAdd("file-staged", "content")
+ shell.CreateFileAndAdd("file-unstaged", "content")
+ shell.EmptyCommit("initial commit")
+ shell.UpdateFileAndAdd("file-staged", "new content")
+ shell.UpdateFile("file-unstaged", "new content")
+ },
+ Run: func(t *TestDriver, keys config.KeybindingConfig) {
+ t.Views().Stash().
+ IsEmpty()
+
+ t.Views().Files().
+ Lines(
+ Contains("file-staged"),
+ Contains("file-unstaged"),
+ ).
+ Press(keys.Files.ViewStashOptions)
+
+ t.ExpectPopup().Menu().Title(Equals("Stash options")).Select(MatchesRegexp("stash unstaged changes$")).Confirm()
+
+ t.ExpectPopup().Prompt().Title(Equals("Stash changes")).Type("my stashed file").Confirm()
+
+ t.Views().Stash().
+ Lines(
+ Contains("my stashed file"),
+ )
+
+ t.Views().Files().
+ Lines(
+ Contains("file-staged"),
+ )
+
+ t.Views().Stash().
+ Focus().
+ PressEnter()
+
+ t.Views().CommitFiles().
+ IsFocused().
+ Lines(
+ Contains("file-unstaged").IsSelected(),
+ )
+ },
+})
diff --git a/pkg/integration/tests/tests_gen.go b/pkg/integration/tests/tests_gen.go
index 27ca095c1..c7cf462fe 100644
--- a/pkg/integration/tests/tests_gen.go
+++ b/pkg/integration/tests/tests_gen.go
@@ -81,9 +81,18 @@ var tests = []*components.IntegrationTest{
misc.ConfirmOnQuit,
misc.InitialOpen,
patch_building.CopyPatchToClipboard,
+ stash.Apply,
+ stash.ApplyPatch,
+ stash.CreateBranch,
+ stash.Drop,
+ stash.Pop,
stash.Rename,
stash.Stash,
+ stash.StashAll,
+ stash.StashAndKeepIndex,
stash.StashIncludingUntrackedFiles,
+ stash.StashStaged,
+ stash.StashUnstaged,
submodule.Add,
submodule.Enter,
submodule.Remove,