1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-07 13:42:01 +02:00

Allow rewording the head commit during interactive rebase

This commit is contained in:
Stefan Haller 2023-03-03 19:53:15 +01:00
parent 605bc026a1
commit b24955063c
6 changed files with 106 additions and 2 deletions

View File

@ -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)
}

View File

@ -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())
}

View File

@ -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())
}

View File

@ -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"),
)
},
})

View File

@ -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"),
)
},
})

View File

@ -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,