diff options
-rw-r--r-- | pkg/commands/git_commands/commit.go | 6 | ||||
-rw-r--r-- | pkg/commands/git_commands/patch.go | 34 | ||||
-rw-r--r-- | pkg/commands/git_commands/rebase.go | 75 | ||||
-rw-r--r-- | pkg/gui/commits_panel.go | 10 | ||||
-rw-r--r-- | pkg/gui/keybindings.go | 2 | ||||
-rw-r--r-- | pkg/i18n/chinese.go | 1 | ||||
-rw-r--r-- | pkg/i18n/dutch.go | 1 | ||||
-rw-r--r-- | pkg/i18n/english.go | 2 | ||||
-rw-r--r-- | pkg/i18n/polish.go | 1 |
9 files changed, 61 insertions, 71 deletions
diff --git a/pkg/commands/git_commands/commit.go b/pkg/commands/git_commands/commit.go index 5b36d7950..866634013 100644 --- a/pkg/commands/git_commands/commit.go +++ b/pkg/commands/git_commands/commit.go @@ -24,9 +24,9 @@ func NewCommitCommands( } } -// RewordLastCommit renames the topmost commit with the given name -func (self *CommitCommands) RewordLastCommit(name string) error { - return self.cmd.New("git commit --allow-empty --amend --only -m " + self.cmd.Quote(name)).Run() +// RewordLastCommit rewords the topmost commit with the given message +func (self *CommitCommands) RewordLastCommit(message string) error { + return self.cmd.New("git commit --allow-empty --amend --only -m " + self.cmd.Quote(message)).Run() } // ResetToCommit reset to commit diff --git a/pkg/commands/git_commands/patch.go b/pkg/commands/git_commands/patch.go index 2949c6ac2..64661cd71 100644 --- a/pkg/commands/git_commands/patch.go +++ b/pkg/commands/git_commands/patch.go @@ -51,7 +51,7 @@ func (self *PatchCommands) DeletePatchesFromCommit(commits []*models.Commit, com // apply each patch in reverse if err := self.PatchManager.ApplyPatches(true); err != nil { - if err := self.rebase.GenericMergeOrRebaseAction("rebase", "abort"); err != nil { + if err := self.rebase.AbortRebase(); err != nil { return err } return err @@ -68,7 +68,7 @@ func (self *PatchCommands) DeletePatchesFromCommit(commits []*models.Commit, com } // continue - return self.rebase.GenericMergeOrRebaseAction("rebase", "continue") + return self.rebase.ContinueRebase() } func (self *PatchCommands) MovePatchToSelectedCommit(commits []*models.Commit, sourceCommitIdx int, destinationCommitIdx int) error { @@ -79,7 +79,7 @@ func (self *PatchCommands) MovePatchToSelectedCommit(commits []*models.Commit, s // apply each patch forward if err := self.PatchManager.ApplyPatches(false); err != nil { - if err := self.rebase.GenericMergeOrRebaseAction("rebase", "abort"); err != nil { + if err := self.rebase.AbortRebase(); err != nil { return err } return err @@ -96,7 +96,7 @@ func (self *PatchCommands) MovePatchToSelectedCommit(commits []*models.Commit, s } // continue - return self.rebase.GenericMergeOrRebaseAction("rebase", "continue") + return self.rebase.ContinueRebase() } if len(commits)-1 < sourceCommitIdx { @@ -120,18 +120,14 @@ func (self *PatchCommands) MovePatchToSelectedCommit(commits []*models.Commit, s todo = a + " " + commit.Sha + " " + commit.Name + "\n" + todo } - cmdObj, err := self.rebase.PrepareInteractiveRebaseCommand(commits[baseIndex].Sha, todo, true) + err := self.rebase.PrepareInteractiveRebaseCommand(commits[baseIndex].Sha, todo, true).Run() if err != nil { return err } - if err := cmdObj.Run(); err != nil { - return err - } - // apply each patch in reverse if err := self.PatchManager.ApplyPatches(true); err != nil { - if err := self.rebase.GenericMergeOrRebaseAction("rebase", "abort"); err != nil { + if err := self.rebase.AbortRebase(); err != nil { return err } return err @@ -150,7 +146,7 @@ func (self *PatchCommands) MovePatchToSelectedCommit(commits []*models.Commit, s // now we should be up to the destination, so let's apply forward these patches to that. // ideally we would ensure we're on the right commit but I'm not sure if that check is necessary if err := self.PatchManager.ApplyPatches(false); err != nil { - if err := self.rebase.GenericMergeOrRebaseAction("rebase", "abort"); err != nil { + if err := self.rebase.AbortRebase(); err != nil { return err } return err @@ -166,10 +162,10 @@ func (self *PatchCommands) MovePatchToSelectedCommit(commits []*models.Commit, s return nil } - return self.rebase.GenericMergeOrRebaseAction("rebase", "continue") + return self.rebase.ContinueRebase() } - return self.rebase.GenericMergeOrRebaseAction("rebase", "continue") + return self.rebase.ContinueRebase() } func (self *PatchCommands) MovePatchIntoIndex(commits []*models.Commit, commitIdx int, stash bool) error { @@ -185,7 +181,7 @@ func (self *PatchCommands) MovePatchIntoIndex(commits []*models.Commit, commitId if err := self.PatchManager.ApplyPatches(true); err != nil { if self.status.WorkingTreeState() == enums.REBASE_MODE_REBASING { - if err := self.rebase.GenericMergeOrRebaseAction("rebase", "abort"); err != nil { + if err := self.rebase.AbortRebase(); err != nil { return err } } @@ -205,7 +201,7 @@ func (self *PatchCommands) MovePatchIntoIndex(commits []*models.Commit, commitId // add patches to index if err := self.PatchManager.ApplyPatches(false); err != nil { if self.status.WorkingTreeState() == enums.REBASE_MODE_REBASING { - if err := self.rebase.GenericMergeOrRebaseAction("rebase", "abort"); err != nil { + if err := self.rebase.AbortRebase(); err != nil { return err } } @@ -222,7 +218,7 @@ func (self *PatchCommands) MovePatchIntoIndex(commits []*models.Commit, commitId return nil } - return self.rebase.GenericMergeOrRebaseAction("rebase", "continue") + return self.rebase.ContinueRebase() } func (self *PatchCommands) PullPatchIntoNewCommit(commits []*models.Commit, commitIdx int) error { @@ -231,7 +227,7 @@ func (self *PatchCommands) PullPatchIntoNewCommit(commits []*models.Commit, comm } if err := self.PatchManager.ApplyPatches(true); err != nil { - if err := self.rebase.GenericMergeOrRebaseAction("rebase", "abort"); err != nil { + if err := self.rebase.AbortRebase(); err != nil { return err } return err @@ -244,7 +240,7 @@ func (self *PatchCommands) PullPatchIntoNewCommit(commits []*models.Commit, comm // add patches to index if err := self.PatchManager.ApplyPatches(false); err != nil { - if err := self.rebase.GenericMergeOrRebaseAction("rebase", "abort"); err != nil { + if err := self.rebase.AbortRebase(); err != nil { return err } return err @@ -262,5 +258,5 @@ func (self *PatchCommands) PullPatchIntoNewCommit(commits []*models.Commit, comm } self.PatchManager.Reset() - return self.rebase.GenericMergeOrRebaseAction("rebase", "continue") + return self.rebase.ContinueRebase() } diff --git a/pkg/commands/git_commands/rebase.go b/pkg/commands/git_commands/rebase.go index 08c8b4cb5..b939b34f5 100644 --- a/pkg/commands/git_commands/rebase.go +++ b/pkg/commands/git_commands/rebase.go @@ -45,13 +45,33 @@ func NewRebaseCommands( } } -func (self *RebaseCommands) RewordCommit(commits []*models.Commit, index int) (oscommands.ICmdObj, error) { +func (self *RebaseCommands) RewordCommit(commits []*models.Commit, index int, message string) error { + if index == 0 { + // we've selected the top commit so no rebase is required + return self.commit.RewordLastCommit(message) + } + + err := self.BeginInteractiveRebaseForCommit(commits, index) + if err != nil { + return err + } + + // now the selected commit should be our head so we'll amend it with the new message + err = self.commit.RewordLastCommit(message) + if err != nil { + return err + } + + return self.ContinueRebase() +} + +func (self *RebaseCommands) RewordCommitInEditor(commits []*models.Commit, index int) (oscommands.ICmdObj, error) { todo, sha, err := self.GenerateGenericRebaseTodo(commits, index, "reword") if err != nil { return nil, err } - return self.PrepareInteractiveRebaseCommand(sha, todo, false) + return self.PrepareInteractiveRebaseCommand(sha, todo, false), nil } func (self *RebaseCommands) MoveCommitDown(commits []*models.Commit, index int) error { @@ -67,12 +87,7 @@ func (self *RebaseCommands) MoveCommitDown(commits []*models.Commit, index int) todo = "pick " + commit.Sha + " " + commit.Name + "\n" + todo } - cmdObj, err := self.PrepareInteractiveRebaseCommand(commits[index+2].Sha, todo, true) - if err != nil { - return err - } - - return cmdObj.Run() + return self.PrepareInteractiveRebaseCommand(commits[index+2].Sha, todo, true).Run() } func (self *RebaseCommands) InteractiveRebase(commits []*models.Commit, index int, action string) error { @@ -81,18 +96,13 @@ func (self *RebaseCommands) InteractiveRebase(commits []*models.Commit, index in return err } - cmdObj, err := self.PrepareInteractiveRebaseCommand(sha, todo, true) - if err != nil { - return err - } - - return cmdObj.Run() + return self.PrepareInteractiveRebaseCommand(sha, todo, true).Run() } // PrepareInteractiveRebaseCommand returns the cmd for an interactive rebase // we tell git to run lazygit to edit the todo list, and we pass the client // lazygit a todo string to write to the todo file -func (self *RebaseCommands) PrepareInteractiveRebaseCommand(baseSha string, todo string, overrideEditor bool) (oscommands.ICmdObj, error) { +func (self *RebaseCommands) PrepareInteractiveRebaseCommand(baseSha string, todo string, overrideEditor bool) oscommands.ICmdObj { ex := oscommands.GetLazygitPath() debug := "FALSE" @@ -125,7 +135,7 @@ func (self *RebaseCommands) PrepareInteractiveRebaseCommand(baseSha string, todo cmdObj.AddEnvVars("GIT_EDITOR=" + ex) } - return cmdObj, nil + return cmdObj } func (self *RebaseCommands) GenerateGenericRebaseTodo(commits []*models.Commit, actionIndex int, action string) (string, string, error) { @@ -235,7 +245,7 @@ func (self *RebaseCommands) SquashAllAboveFixupCommits(sha string) error { } // BeginInteractiveRebaseForCommit starts an interactive rebase to edit the current -// commit and pick all others. After this you'll want to call `self.GenericMergeOrRebaseAction("rebase", "continue")` +// commit and pick all others. After this you'll want to call `self.ContinueRebase() func (self *RebaseCommands) BeginInteractiveRebaseForCommit(commits []*models.Commit, commitIndex int) error { if len(commits)-1 < commitIndex { return errors.New("index outside of range of commits") @@ -253,28 +263,26 @@ func (self *RebaseCommands) BeginInteractiveRebaseForCommit(commits []*models.Co return err } - cmdObj, err := self.PrepareInteractiveRebaseCommand(sha, todo, true) - if err != nil { - return err - } - - return cmdObj.Run() + return self.PrepareInteractiveRebaseCommand(sha, todo, true).Run() } // RebaseBranch interactive rebases onto a branch func (self *RebaseCommands) RebaseBranch(branchName string) error { - cmdObj, err := self.PrepareInteractiveRebaseCommand(branchName, "", false) - if err != nil { - return err - } - - return cmdObj.Run() + return self.PrepareInteractiveRebaseCommand(branchName, "", false).Run() } func (self *RebaseCommands) GenericMergeOrRebaseActionCmdObj(commandType string, command string) oscommands.ICmdObj { return self.cmd.New("git " + commandType + " --" + command) } +func (self *RebaseCommands) ContinueRebase() error { + return self.GenericMergeOrRebaseAction("rebase", "continue") +} + +func (self *RebaseCommands) AbortRebase() error { + return self.GenericMergeOrRebaseAction("rebase", "abort") +} + // GenericMerge takes a commandType of "merge" or "rebase" and a command of "abort", "skip" or "continue" // By default we skip the editor in the case where a commit will be made func (self *RebaseCommands) GenericMergeOrRebaseAction(commandType string, command string) error { @@ -337,7 +345,7 @@ func (self *RebaseCommands) DiscardOldFileChanges(commits []*models.Commit, comm } // continue - return self.GenericMergeOrRebaseAction("rebase", "continue") + return self.ContinueRebase() } // CherryPickCommits begins an interactive rebase with the given shas being cherry picked onto HEAD @@ -347,10 +355,5 @@ func (self *RebaseCommands) CherryPickCommits(commits []*models.Commit) error { todo = "pick " + commit.Sha + " " + commit.Name + "\n" + todo } - cmdObj, err := self.PrepareInteractiveRebaseCommand("HEAD", todo, false) - if err != nil { - return err - } - - return cmdObj.Run() + return self.PrepareInteractiveRebaseCommand("HEAD", todo, false).Run() } diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go index fcc49d839..b933dc5c8 100644 --- a/pkg/gui/commits_panel.go +++ b/pkg/gui/commits_panel.go @@ -221,10 +221,6 @@ func (gui *Gui) handleRewordCommit() error { return nil } - if gui.State.Panels.Commits.SelectedLineIdx != 0 { - return gui.createErrorPanel(gui.Tr.OnlyRewordTopCommit) - } - commit := gui.getSelectedLocalCommit() if commit == nil { return nil @@ -240,7 +236,7 @@ func (gui *Gui) handleRewordCommit() error { initialContent: message, handleConfirm: func(response string) error { gui.logAction(gui.Tr.Actions.RewordCommit) - if err := gui.Git.Commit.RewordLastCommit(response); err != nil { + if err := gui.Git.Rebase.RewordCommit(gui.State.Commits, gui.State.Panels.Commits.SelectedLineIdx, response); err != nil { return gui.surfaceError(err) } @@ -249,7 +245,7 @@ func (gui *Gui) handleRewordCommit() error { }) } -func (gui *Gui) handleRenameCommitEditor() error { +func (gui *Gui) handleRewordCommitEditor() error { if ok, err := gui.validateNotInFilterMode(); err != nil || !ok { return err } @@ -263,7 +259,7 @@ func (gui *Gui) handleRenameCommitEditor() error { } gui.logAction(gui.Tr.Actions.RewordCommit) - subProcess, err := gui.Git.Rebase.RewordCommit(gui.State.Commits, gui.State.Panels.Commits.SelectedLineIdx) + subProcess, err := gui.Git.Rebase.RewordCommitInEditor(gui.State.Commits, gui.State.Panels.Commits.SelectedLineIdx) if err != nil { return gui.surfaceError(err) } diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 896349dae..a3e998416 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -750,7 +750,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { ViewName: "commits", Contexts: []string{string(BRANCH_COMMITS_CONTEXT_KEY)}, Key: gui.getKey(config.Commits.RenameCommitWithEditor), - Handler: gui.handleRenameCommitEditor, + Handler: gui.handleRewordCommitEditor, Description: gui.Tr.LcRenameCommitEditor, }, { diff --git a/pkg/i18n/chinese.go b/pkg/i18n/chinese.go index 117f1f6c8..3167e0bf8 100644 --- a/pkg/i18n/chinese.go +++ b/pkg/i18n/chinese.go @@ -109,7 +109,6 @@ func chineseTranslationSet() TranslationSet { Squash: "压缩", LcPickCommit: "选择提交(变基过程中)", LcRevertCommit: "还原提交", - OnlyRewordTopCommit: "只能从 lazygit 内部重写最高的提交。请使用 shift-R", LcRewordCommit: "改写提交", LcDeleteCommit: "删除提交", LcMoveDownCommit: "下移提交", diff --git a/pkg/i18n/dutch.go b/pkg/i18n/dutch.go index f2f270dff..914d558fe 100644 --- a/pkg/i18n/dutch.go +++ b/pkg/i18n/dutch.go @@ -79,7 +79,6 @@ func dutchTranslationSet() TranslationSet { Squash: "Squash", LcPickCommit: "kies commit (wanneer midden in rebase)", LcRevertCommit: "commit ongedaan maken", - OnlyRewordTopCommit: "Je kan alleen de bovenste commit hernoemen", LcRewordCommit: "hernoem commit", LcDeleteCommit: "verwijder commit", LcMoveDownCommit: "verplaats commit 1 naar beneden", diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 7cf9d17b8..2defb4ae6 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -93,7 +93,6 @@ type TranslationSet struct { Squash string LcPickCommit string LcRevertCommit string - OnlyRewordTopCommit string LcRewordCommit string LcDeleteCommit string LcMoveDownCommit string @@ -645,7 +644,6 @@ func EnglishTranslationSet() TranslationSet { Squash: "Squash", LcPickCommit: "pick commit (when mid-rebase)", LcRevertCommit: "revert commit", - OnlyRewordTopCommit: "Can only reword topmost commit from within lazygit. Use shift+R instead", LcRewordCommit: "reword commit", LcDeleteCommit: "delete commit", LcMoveDownCommit: "move commit down one", diff --git a/pkg/i18n/polish.go b/pkg/i18n/polish.go index 88970215f..5994a59e9 100644 --- a/pkg/i18n/polish.go +++ b/pkg/i18n/polish.go @@ -69,7 +69,6 @@ func polishTranslationSet() TranslationSet { YouNoCommitsToSquash: "Nie masz commitów do spłaszczenia", Fixup: "Napraw", SureFixupThisCommit: "Jesteś pewny, ze chcesz naprawić ten commit? Commit poniżej zostanie spłaszczony w górę wraz z tym", - OnlyRewordTopCommit: "Można zmienić nazwę tylko ostatniemu commitowi", LcRewordCommit: "zmień nazwę commita", LcRenameCommitEditor: "zmień nazwę commita w edytorze", Error: "Błąd", |