summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuka Markušić <luka.markusic@microblink.com>2022-09-15 17:35:33 +0200
committerStefan Haller <stefan@haller-berlin.de>2023-04-01 08:16:15 +0200
commite7d0116312ff3233ff19bc3b355e7cb5f7b570ac (patch)
tree33a5596982a5beac5f2c444d505bad38db3bde4f
parent85fdb700ba9fd69393f1e7ee572cc6b0d741aaf5 (diff)
Allow amending the head commit during interactive rebase
-rw-r--r--pkg/gui/controllers/local_commits_controller.go7
-rw-r--r--pkg/integration/tests/interactive_rebase/amend_head_commit_during_rebase.go59
-rw-r--r--pkg/integration/tests/interactive_rebase/amend_merge.go4
-rw-r--r--pkg/integration/tests/test_list.go1
4 files changed, 69 insertions, 2 deletions
diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go
index 348e0e73f..355e18b82 100644
--- a/pkg/gui/controllers/local_commits_controller.go
+++ b/pkg/gui/controllers/local_commits_controller.go
@@ -445,6 +445,13 @@ func (self *LocalCommitsController) moveUp(commit *models.Commit) error {
}
func (self *LocalCommitsController) amendTo(commit *models.Commit) error {
+ if self.isHeadCommit() {
+ if err := self.helpers.AmendHelper.AmendHead(); err != nil {
+ return err
+ }
+ return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
+ }
+
return self.c.Confirm(types.ConfirmOpts{
Title: self.c.Tr.AmendCommitTitle,
Prompt: self.c.Tr.AmendCommitPrompt,
diff --git a/pkg/integration/tests/interactive_rebase/amend_head_commit_during_rebase.go b/pkg/integration/tests/interactive_rebase/amend_head_commit_during_rebase.go
new file mode 100644
index 000000000..4f0a024c0
--- /dev/null
+++ b/pkg/integration/tests/interactive_rebase/amend_head_commit_during_rebase.go
@@ -0,0 +1,59 @@
+package interactive_rebase
+
+import (
+ "github.com/jesseduffield/lazygit/pkg/config"
+ . "github.com/jesseduffield/lazygit/pkg/integration/components"
+)
+
+var AmendHeadCommitDuringRebase = NewIntegrationTest(NewIntegrationTestArgs{
+ Description: "Amends the current head commit from the commits panel during a rebase.",
+ ExtraCmdArgs: "",
+ Skip: false,
+ SetupConfig: func(config *config.AppConfig) {},
+ SetupRepo: func(shell *Shell) {
+ shell.CreateNCommits(3)
+ },
+ Run: func(t *TestDriver, keys config.KeybindingConfig) {
+ t.Views().Commits().
+ Focus().
+ Lines(
+ Contains("commit 03"),
+ Contains("commit 02"),
+ Contains("commit 01"),
+ ).
+ NavigateToLine(Contains("commit 02")).
+ Press(keys.Universal.Edit).
+ Lines(
+ Contains("commit 03"),
+ Contains("<-- YOU ARE HERE --- commit 02").IsSelected(),
+ Contains("commit 01"),
+ )
+
+ t.Shell().CreateFile("fixup-file", "fixup content")
+ t.Views().Files().
+ Focus().
+ Press(keys.Files.RefreshFiles).
+ Lines(
+ Contains("??").Contains("fixup-file").IsSelected(),
+ ).
+ PressPrimaryAction()
+
+ t.Views().Commits().
+ Focus().
+ Press(keys.Commits.AmendToCommit).
+ Tap(func() {
+ t.ExpectPopup().Confirmation().
+ Title(Equals("Amend Last Commit")).
+ Content(Contains("Are you sure you want to amend last commit?")).
+ Confirm()
+ }).
+ Lines(
+ Contains("commit 03"),
+ Contains("<-- YOU ARE HERE --- commit 02").IsSelected(),
+ Contains("commit 01"),
+ )
+
+ t.Views().Main().
+ Content(Contains("fixup content"))
+ },
+})
diff --git a/pkg/integration/tests/interactive_rebase/amend_merge.go b/pkg/integration/tests/interactive_rebase/amend_merge.go
index 7e5e64746..b0def4f7a 100644
--- a/pkg/integration/tests/interactive_rebase/amend_merge.go
+++ b/pkg/integration/tests/interactive_rebase/amend_merge.go
@@ -42,8 +42,8 @@ var AmendMerge = NewIntegrationTest(NewIntegrationTestArgs{
Press(keys.Commits.AmendToCommit)
t.ExpectPopup().Confirmation().
- Title(Equals("Amend Commit")).
- Content(Contains("Are you sure you want to amend this commit with your staged files?")).
+ Title(Equals("Amend Last Commit")).
+ Content(Contains("Are you sure you want to amend last commit?")).
Confirm()
// assuring we haven't added a brand new commit
diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go
index 43affe57a..75eaaec52 100644
--- a/pkg/integration/tests/test_list.go
+++ b/pkg/integration/tests/test_list.go
@@ -82,6 +82,7 @@ var tests = []*components.IntegrationTest{
filter_by_path.SelectFile,
filter_by_path.TypeFile,
interactive_rebase.AmendFirstCommit,
+ interactive_rebase.AmendHeadCommitDuringRebase,
interactive_rebase.AmendMerge,
interactive_rebase.EditFirstCommit,
interactive_rebase.EditNonTodoCommitDuringRebase,