summaryrefslogtreecommitdiffstats
path: root/pkg/integration/tests
diff options
context:
space:
mode:
authorAaron Hoffman <kd0sgh@gmail.com>2024-01-28 09:15:29 -0600
committerAaron Hoffman <kd0sgh@gmail.com>2024-02-13 09:10:15 -0600
commit15d5261933912f0665ca1920f5131dce9cc2dbb3 (patch)
tree434e054045aaa72d1bad42cfd517c6afe5af213b /pkg/integration/tests
parentbeb730a9e6f9113db3cb22b222f4858f95dc4d55 (diff)
Support range select removing files from a commit
Diffstat (limited to 'pkg/integration/tests')
-rw-r--r--pkg/integration/tests/commit/discard_old_file_change.go2
-rw-r--r--pkg/integration/tests/commit/discard_range_select.go131
-rw-r--r--pkg/integration/tests/test_list.go1
3 files changed, 133 insertions, 1 deletions
diff --git a/pkg/integration/tests/commit/discard_old_file_change.go b/pkg/integration/tests/commit/discard_old_file_change.go
index 5d5fcc0c8..0b215d735 100644
--- a/pkg/integration/tests/commit/discard_old_file_change.go
+++ b/pkg/integration/tests/commit/discard_old_file_change.go
@@ -43,7 +43,7 @@ var DiscardOldFileChange = NewIntegrationTest(NewIntegrationTestArgs{
t.ExpectPopup().Confirmation().
Title(Equals("Discard file changes")).
- Content(Equals("Are you sure you want to discard this commit's changes to this file? The file was added in this commit, so it will be deleted again.")).
+ 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().
diff --git a/pkg/integration/tests/commit/discard_range_select.go b/pkg/integration/tests/commit/discard_range_select.go
new file mode 100644
index 000000000..65b50a6be
--- /dev/null
+++ b/pkg/integration/tests/commit/discard_range_select.go
@@ -0,0 +1,131 @@
+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 cfadde3b1..48a0572b9 100644
--- a/pkg/integration/tests/test_list.go
+++ b/pkg/integration/tests/test_list.go
@@ -71,6 +71,7 @@ var tests = []*components.IntegrationTest{
commit.CommitWithPrefix,
commit.CreateTag,
commit.DiscardOldFileChange,
+ commit.DiscardRangeSelect,
commit.FindBaseCommitForFixup,
commit.FindBaseCommitForFixupWarningForAddedLines,
commit.Highlight,