summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Hoffman <kd0sgh@gmail.com>2024-01-30 13:52:40 -0600
committerAaron Hoffman <kd0sgh@gmail.com>2024-02-13 09:10:15 -0600
commitd138f7ce86ec61023c5794f491e362e3fe26e217 (patch)
treef21c0d10327541230097e8a768bad6926cdda259
parent62a0c895b47ad7ee0c072a053942af41d214f772 (diff)
Clean up test case
I'm combining the delete single file case from `discard_old_file_change` with the content of `discard_range_select` and calling that `discard_old_file_changes`. Hopefully that cleans things up a little bit. This also adds a check that the custom patch is getting reset properly.
-rw-r--r--pkg/integration/tests/commit/discard_old_file_change.go57
-rw-r--r--pkg/integration/tests/commit/discard_old_file_changes.go173
-rw-r--r--pkg/integration/tests/commit/discard_range_select.go131
-rw-r--r--pkg/integration/tests/test_list.go3
4 files changed, 174 insertions, 190 deletions
diff --git a/pkg/integration/tests/commit/discard_old_file_change.go b/pkg/integration/tests/commit/discard_old_file_change.go
deleted file mode 100644
index 0b215d735..000000000
--- a/pkg/integration/tests/commit/discard_old_file_change.go
+++ /dev/null
@@ -1,57 +0,0 @@
-package commit
-
-import (
- "github.com/jesseduffield/lazygit/pkg/config"
- . "github.com/jesseduffield/lazygit/pkg/integration/components"
-)
-
-var DiscardOldFileChange = NewIntegrationTest(NewIntegrationTestArgs{
- Description: "Discarding a single file from an old commit (does rebase in background to remove the file but retain the other one)",
- ExtraCmdArgs: []string{},
- Skip: false,
- SetupConfig: func(config *config.AppConfig) {},
- SetupRepo: func(shell *Shell) {
- shell.CreateFileAndAdd("file0", "file0")
- shell.Commit("first commit")
-
- shell.CreateFileAndAdd("file1", "file2")
- shell.CreateFileAndAdd("fileToRemove", "fileToRemove")
- shell.Commit("commit to change")
-
- shell.CreateFileAndAdd("file3", "file3")
- shell.Commit("third commit")
- },
- Run: func(t *TestDriver, keys config.KeybindingConfig) {
- t.Views().Commits().
- Focus().
- Lines(
- Contains("third commit").IsSelected(),
- Contains("commit to change"),
- Contains("first commit"),
- ).
- SelectNextItem().
- PressEnter()
-
- t.Views().CommitFiles().
- IsFocused().
- Lines(
- Contains("file1").IsSelected(),
- Contains("fileToRemove"),
- ).
- SelectNextItem().
- Press(keys.Universal.Remove)
-
- t.ExpectPopup().Confirmation().
- Title(Equals("Discard file changes")).
- Content(Equals("Are you sure you want to remove changes to the selected file(s) from this commit?\n\nThis action will start a rebase, reverting these file changes. Be aware that if subsequent commits depend on these changes, you may need to resolve conflicts.\nNote: This will also reset any active custom patches.")).
- Confirm()
-
- t.Views().CommitFiles().
- IsFocused().
- Lines(
- Contains("file1").IsSelected(),
- )
-
- t.FileSystem().PathNotPresent("fileToRemove")
- },
-})
diff --git a/pkg/integration/tests/commit/discard_old_file_changes.go b/pkg/integration/tests/commit/discard_old_file_changes.go
new file mode 100644
index 000000000..4b97a30b7
--- /dev/null
+++ b/pkg/integration/tests/commit/discard_old_file_changes.go
@@ -0,0 +1,173 @@
+package commit
+
+import (
+ "github.com/jesseduffield/lazygit/pkg/config"
+ . "github.com/jesseduffield/lazygit/pkg/integration/components"
+)
+
+var DiscardOldFileChanges = NewIntegrationTest(NewIntegrationTestArgs{
+ Description: "Discarding a range of files from an old commit.",
+ ExtraCmdArgs: []string{},
+ Skip: false,
+ SetupConfig: func(config *config.AppConfig) {},
+ SetupRepo: func(shell *Shell) {
+ shell.CreateFileAndAdd("dir1/d1_file0", "file0\n")
+ shell.CreateFileAndAdd("dir1/subd1/subfile0", "file1\n")
+ shell.CreateFileAndAdd("dir2/d2_file1", "d2f1 content\n")
+ shell.CreateFileAndAdd("dir2/d2_file2", "d2f4 content\n")
+ shell.Commit("remove one file from this commit")
+
+ shell.UpdateFileAndAdd("dir2/d2_file1", "d2f1 content\nsecond line\n")
+ shell.DeleteFileAndAdd("dir2/d2_file2")
+ shell.CreateFileAndAdd("dir2/d2_file3", "d2f3 content\n")
+ shell.CreateFileAndAdd("dir2/d2_file4", "d2f2 content\n")
+ shell.Commit("remove four files from this commit")
+
+ shell.CreateFileAndAdd("dir1/fileToRemove", "file to remove content\n")
+ shell.CreateFileAndAdd("dir1/multiLineFile", "this file has\ncontent on\nthree lines\n")
+ shell.CreateFileAndAdd("dir1/subd1/file2ToRemove", "file2 to remove content\n")
+ shell.Commit("remove changes in multiple dirs from this commit")
+ },
+ Run: func(t *TestDriver, keys config.KeybindingConfig) {
+ t.Views().Commits().
+ Focus().
+ Lines(
+ Contains("remove changes in multiple dirs from this commit").IsSelected(),
+ Contains("remove four files from this commit"),
+ Contains("remove one file from this commit"),
+ ).
+ NavigateToLine(Contains("remove one file from this commit")).
+ PressEnter()
+
+ // Check removing a single file from an old commit
+ t.Views().CommitFiles().
+ IsFocused().
+ Lines(
+ Contains("dir1").IsSelected(),
+ Contains("subd1"),
+ Contains("subfile0"),
+ Contains("d1_file0"),
+ Contains("dir2"),
+ Contains("d2_file1"),
+ Contains("d2_file2"),
+ ).
+ NavigateToLine(Contains("d1_file0")).
+ Press(keys.Universal.Remove)
+
+ t.ExpectPopup().Confirmation().
+ Title(Equals("Discard file changes")).
+ Content(Equals("Are you sure you want to remove changes to the selected file(s) from this commit?\n\nThis action will start a rebase, reverting these file changes. Be aware that if subsequent commits depend on these changes, you may need to resolve conflicts.\nNote: This will also reset any active custom patches.")).
+ Confirm()
+
+ t.Views().CommitFiles().
+ IsFocused().
+ Lines(
+ Contains("dir1/subd1"),
+ Contains("subfile0"),
+ Contains("dir2"),
+ Contains("d2_file1").IsSelected(),
+ Contains("d2_file2"),
+ ).
+ PressEscape()
+
+ // Check removing 4 files in the same directory
+ t.Views().Commits().
+ Focus().
+ Lines(
+ Contains("remove changes in multiple dirs from this commit"),
+ Contains("remove four files from this commit"),
+ Contains("remove one file from this commit").IsSelected(),
+ ).
+ NavigateToLine(Contains("remove four files from this commit")).
+ PressEnter()
+
+ t.Views().CommitFiles().
+ IsFocused().
+ Lines(
+ Contains("dir2").IsSelected(),
+ Contains("d2_file1"),
+ Contains("d2_file2"),
+ Contains("d2_file3"),
+ Contains("d2_file4"),
+ ).
+ NavigateToLine(Contains("d2_file1")).
+ Press(keys.Universal.ToggleRangeSelect).
+ NavigateToLine(Contains("d2_file4")).
+ Press(keys.Universal.Remove)
+
+ t.ExpectPopup().Confirmation().
+ Title(Equals("Discard file changes")).
+ Content(Equals("Are you sure you want to remove changes to the selected file(s) from this commit?\n\nThis action will start a rebase, reverting these file changes. Be aware that if subsequent commits depend on these changes, you may need to resolve conflicts.\nNote: This will also reset any active custom patches.")).
+ Confirm()
+
+ t.Views().CommitFiles().
+ IsFocused().
+ Lines(
+ Contains("(none)"),
+ ).
+ // for some reason I need to press escape twice. Seems like it happens every time
+ // more than one file is removed from a commit
+ PressEscape().
+ PressEscape()
+
+ // Check removing multiple files from 2 directories w/ a custom patch.
+ // This checks node selection logic & if the custom patch is getting reset.
+ t.Views().Commits().
+ IsFocused().
+ Lines(
+ Contains("remove changes in multiple dirs from this commit"),
+ Contains("remove four files from this commit").IsSelected(),
+ Contains("remove one file from this commit"),
+ ).
+ NavigateToLine(Contains("remove changes in multiple dirs from this commit")).
+ PressEnter()
+
+ t.Views().CommitFiles().
+ IsFocused().
+ Lines(
+ Contains("dir1").IsSelected(),
+ Contains("subd1"),
+ Contains("file2ToRemove"),
+ Contains("fileToRemove"),
+ Contains("multiLineFile"),
+ ).
+ NavigateToLine(Contains("multiLineFile")).
+ PressEnter()
+
+ t.Views().PatchBuilding().
+ IsFocused().
+ SelectedLine(
+ Contains("+this file has"),
+ ).
+ PressPrimaryAction().
+ PressEscape()
+
+ t.Views().CommitFiles().
+ IsFocused().
+ Lines(
+ Contains("dir1"),
+ Contains("subd1"),
+ Contains("file2ToRemove"),
+ Contains("fileToRemove"),
+ Contains("multiLineFile").IsSelected(),
+ ).
+ NavigateToLine(Contains("dir1")).
+ Press(keys.Universal.ToggleRangeSelect).
+ NavigateToLine(Contains("subd1")).
+ Press(keys.Universal.Remove)
+
+ t.ExpectPopup().Confirmation().
+ Title(Equals("Discard file changes")).
+ Content(Equals("Are you sure you want to remove changes to the selected file(s) from this commit?\n\nThis action will start a rebase, reverting these file changes. Be aware that if subsequent commits depend on these changes, you may need to resolve conflicts.\nNote: This will also reset any active custom patches.")).
+ Confirm()
+
+ // "Building patch" will still be in this view if the patch isn't reset properly
+ t.Views().Information().Content(DoesNotContain("Building patch"))
+
+ t.Views().CommitFiles().
+ IsFocused().
+ Lines(
+ Contains("(none)"),
+ )
+ },
+})
diff --git a/pkg/integration/tests/commit/discard_range_select.go b/pkg/integration/tests/commit/discard_range_select.go
deleted file mode 100644
index 65b50a6be..000000000
--- a/pkg/integration/tests/commit/discard_range_select.go
+++ /dev/null
@@ -1,131 +0,0 @@
-package commit
-
-import (
- "github.com/jesseduffield/lazygit/pkg/config"
- . "github.com/jesseduffield/lazygit/pkg/integration/components"
-)
-
-var DiscardRangeSelect = NewIntegrationTest(NewIntegrationTestArgs{
- Description: "Discarding a range of files from an old commit.",
- ExtraCmdArgs: []string{},
- Skip: false,
- SetupConfig: func(config *config.AppConfig) {},
- SetupRepo: func(shell *Shell) {
- shell.CreateFileAndAdd("dir1/file0", "file0\n")
- shell.CreateFileAndAdd("dir1/dir2/file1", "file1\n")
- shell.CreateFileAndAdd("dir3/file1", "d3f1 content\n")
- shell.CreateFileAndAdd("dir3/file4", "d3f4 content\n")
- shell.Commit("first commit")
-
- shell.UpdateFileAndAdd("dir3/file1", "d3f1 content\nsecond line\n")
- shell.CreateFileAndAdd("dir3/file2", "d3f2 content\n")
- shell.CreateFileAndAdd("dir3/file3", "d3f3 content\n")
- shell.DeleteFileAndAdd("dir3/file4")
- shell.Commit("first commit to change")
-
- shell.CreateFileAndAdd("dir1/fileToRemove", "file to remove content\n")
- shell.CreateFileAndAdd("dir1/multiLineFile", "this file has\ncontent on\nthree lines\n")
- shell.CreateFileAndAdd("dir1/dir2/file2ToRemove", "file2 to remove content\n")
- shell.Commit("second commit to change")
-
- shell.CreateFileAndAdd("file3", "file3")
- shell.Commit("third commit")
- },
- Run: func(t *TestDriver, keys config.KeybindingConfig) {
- t.Views().Commits().
- Focus().
- Lines(
- Contains("third commit").IsSelected(),
- Contains("second commit to change"),
- Contains("first commit to change"),
- Contains("first commit"),
- ).
- NavigateToLine(Contains("first commit to change")).
- PressEnter()
-
- t.Views().CommitFiles().
- IsFocused().
- Lines(
- Contains("dir3").IsSelected(),
- Contains("file1"),
- Contains("file2"),
- Contains("file3"),
- Contains("file4"),
- ).
- NavigateToLine(Contains("file1")).
- Press(keys.Universal.ToggleRangeSelect).
- NavigateToLine(Contains("file4")).
- Press(keys.Universal.Remove)
-
- t.ExpectPopup().Confirmation().
- Title(Equals("Discard file changes")).
- Content(Equals("Are you sure you want to remove changes to the selected file(s) from this commit?\n\nThis action will start a rebase, reverting these file changes. Be aware that if subsequent commits depend on these changes, you may need to resolve conflicts.\nNote: This will also reset any active custom patches.")).
- Confirm()
-
- t.Views().CommitFiles().
- IsFocused().
- Lines(
- Contains("(none)"),
- ).
- // for some reason I need to press escape twice. Seems like it happens every time
- // more than one file is removed from a commit
- PressEscape().
- PressEscape()
-
- t.Views().Commits().
- IsFocused().
- Lines(
- Contains("third commit"),
- Contains("second commit to change"),
- Contains("first commit to change").IsSelected(),
- Contains("first commit"),
- ).
- NavigateToLine(Contains("second commit to change")).
- PressEnter()
-
- t.Views().CommitFiles().
- IsFocused().
- Lines(
- Contains("dir1").IsSelected(),
- Contains("dir2"),
- Contains("file2ToRemove"),
- Contains("fileToRemove"),
- Contains("multiLineFile"),
- ).
- NavigateToLine(Contains("multiLineFile")).
- PressEnter()
-
- t.Views().PatchBuilding().
- IsFocused().
- SelectedLine(
- Contains("+this file has"),
- ).
- PressPrimaryAction().
- PressEscape()
-
- t.Views().CommitFiles().
- IsFocused().
- Lines(
- Contains("dir1"),
- Contains("dir2"),
- Contains("file2ToRemove"),
- Contains("fileToRemove"),
- Contains("multiLineFile").IsSelected(),
- ).
- NavigateToLine(Contains("dir1")).
- Press(keys.Universal.ToggleRangeSelect).
- NavigateToLine(Contains("dir2")).
- Press(keys.Universal.Remove)
-
- t.ExpectPopup().Confirmation().
- Title(Equals("Discard file changes")).
- Content(Equals("Are you sure you want to remove changes to the selected file(s) from this commit?\n\nThis action will start a rebase, reverting these file changes. Be aware that if subsequent commits depend on these changes, you may need to resolve conflicts.\nNote: This will also reset any active custom patches.")).
- Confirm()
-
- t.Views().CommitFiles().
- IsFocused().
- Lines(
- Contains("(none)"),
- )
- },
-})
diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go
index 48a0572b9..6a448fff4 100644
--- a/pkg/integration/tests/test_list.go
+++ b/pkg/integration/tests/test_list.go
@@ -70,8 +70,7 @@ var tests = []*components.IntegrationTest{
commit.CommitWipWithPrefix,
commit.CommitWithPrefix,
commit.CreateTag,
- commit.DiscardOldFileChange,
- commit.DiscardRangeSelect,
+ commit.DiscardOldFileChanges,
commit.FindBaseCommitForFixup,
commit.FindBaseCommitForFixupWarningForAddedLines,
commit.Highlight,