diff options
6 files changed, 106 insertions, 2 deletions
diff --git a/pkg/commands/git_commands/rebase.go b/pkg/commands/git_commands/rebase.go index b0fa939c3..6af83a27f 100644 --- a/pkg/commands/git_commands/rebase.go +++ b/pkg/commands/git_commands/rebase.go @@ -34,7 +34,7 @@ func NewRebaseCommands( } func (self *RebaseCommands) RewordCommit(commits []*models.Commit, index int, message string) error { - if index == 0 { + if models.IsHeadCommit(commits, index) { // we've selected the top commit so no rebase is required return self.commit.RewordLastCommit(message) } diff --git a/pkg/commands/models/commit.go b/pkg/commands/models/commit.go index 3502fab4f..b3a171934 100644 --- a/pkg/commands/models/commit.go +++ b/pkg/commands/models/commit.go @@ -65,3 +65,7 @@ func (c *Commit) IsMerge() bool { func (c *Commit) IsTODO() bool { return c.Action != "" } + +func IsHeadCommit(commits []*Commit, index int) bool { + return !commits[index].IsTODO() && (index == 0 || commits[index-1].IsTODO()) +} diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go index 175c0ea47..904dbfd33 100644 --- a/pkg/gui/controllers/local_commits_controller.go +++ b/pkg/gui/controllers/local_commits_controller.go @@ -229,7 +229,7 @@ func (self *LocalCommitsController) reword(commit *models.Commit) error { func (self *LocalCommitsController) doRewordEditor() error { self.c.LogAction(self.c.Tr.Actions.RewordCommit) - if self.context().GetSelectedLineIdx() == 0 { + if self.isHeadCommit() { return self.c.RunSubprocessAndRefresh(self.os.Cmd.New("git commit --allow-empty --amend --only")) } @@ -728,3 +728,7 @@ func (self *LocalCommitsController) context() *context.LocalCommitsContext { func (self *LocalCommitsController) paste() error { return self.helpers.CherryPick.Paste() } + +func (self *LocalCommitsController) isHeadCommit() bool { + return models.IsHeadCommit(self.model.Commits, self.context().GetSelectedLineIdx()) +} diff --git a/pkg/integration/tests/interactive_rebase/reword_you_are_here_commit.go b/pkg/integration/tests/interactive_rebase/reword_you_are_here_commit.go new file mode 100644 index 000000000..921e1a016 --- /dev/null +++ b/pkg/integration/tests/interactive_rebase/reword_you_are_here_commit.go @@ -0,0 +1,47 @@ +package interactive_rebase + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var RewordYouAreHereCommit = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Rewords the current HEAD commit in an interactive 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").IsSelected(), + 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"), + ). + Press(keys.Commits.RenameCommit). + Tap(func() { + t.ExpectPopup().Prompt(). + Title(Equals("reword commit")). + InitialText(Equals("commit 02")). + Clear(). + Type("renamed 02"). + Confirm() + }). + Lines( + Contains("commit 03"), + Contains("<-- YOU ARE HERE --- renamed 02").IsSelected(), + Contains("commit 01"), + ) + }, +}) diff --git a/pkg/integration/tests/interactive_rebase/reword_you_are_here_commit_with_editor.go b/pkg/integration/tests/interactive_rebase/reword_you_are_here_commit_with_editor.go new file mode 100644 index 000000000..c6e57932a --- /dev/null +++ b/pkg/integration/tests/interactive_rebase/reword_you_are_here_commit_with_editor.go @@ -0,0 +1,47 @@ +package interactive_rebase + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var RewordYouAreHereCommitWithEditor = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Rewords the current HEAD commit in an interactive rebase with editor", + ExtraCmdArgs: "", + Skip: false, + SetupConfig: func(config *config.AppConfig) { + }, + SetupRepo: func(shell *Shell) { + shell. + CreateNCommits(3). + SetConfig("core.editor", "sh -c 'echo renamed 02 >.git/COMMIT_EDITMSG'") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Commits(). + Focus(). + Lines( + Contains("commit 03").IsSelected(), + 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"), + ). + Press(keys.Commits.RenameCommitWithEditor). + Tap(func() { + t.ExpectPopup().Confirmation(). + Title(Equals("Reword in editor")). + Content(Contains("Are you sure you want to reword this commit in your editor?")). + Confirm() + }). + Lines( + Contains("commit 03"), + Contains("<-- YOU ARE HERE --- renamed 02").IsSelected(), + Contains("commit 01"), + ) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 807c5810d..f0ec4b78c 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -90,6 +90,8 @@ var tests = []*components.IntegrationTest{ interactive_rebase.Rebase, interactive_rebase.RewordFirstCommit, interactive_rebase.RewordLastCommit, + interactive_rebase.RewordYouAreHereCommit, + interactive_rebase.RewordYouAreHereCommitWithEditor, interactive_rebase.SquashDownFirstCommit, interactive_rebase.SquashDownSecondCommit, interactive_rebase.SquashFixupsAboveFirstCommit, |