diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-06-05 16:39:59 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-06-05 22:15:51 +1000 |
commit | fb395bca6eedfc44afb04ad26005a45e7b7dfea9 (patch) | |
tree | 4669caf828ea97afdb9c829820ff53c5731fcca2 /pkg/gui/commits_panel.go | |
parent | f91adf026bfbddc9505d6d84d3fabc80d49c7ca0 (diff) |
support reverting merge commits
Diffstat (limited to 'pkg/gui/commits_panel.go')
-rw-r--r-- | pkg/gui/commits_panel.go | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go index 01264948e..422d8ec29 100644 --- a/pkg/gui/commits_panel.go +++ b/pkg/gui/commits_panel.go @@ -461,9 +461,43 @@ func (gui *Gui) handleCommitRevert() error { return err } - if err := gui.GitCommand.WithSpan(gui.Tr.Spans.RevertCommit).Revert(gui.State.Commits[gui.State.Panels.Commits.SelectedLineIdx].Sha); err != nil { - return gui.surfaceError(err) + commit := gui.getSelectedLocalCommit() + + if commit.IsMerge() { + return gui.createRevertMergeCommitMenu(commit) + } else { + if err := gui.GitCommand.WithSpan(gui.Tr.Spans.RevertCommit).Revert(commit.Sha); err != nil { + return gui.surfaceError(err) + } + return gui.afterRevertCommit() + } +} + +func (gui *Gui) createRevertMergeCommitMenu(commit *models.Commit) error { + menuItems := make([]*menuItem, len(commit.Parents)) + for i, parentSha := range commit.Parents { + i := i + message, err := gui.GitCommand.GetCommitMessageFirstLine(parentSha) + if err != nil { + return gui.surfaceError(err) + } + + menuItems[i] = &menuItem{ + displayString: fmt.Sprintf("%s: %s", utils.SafeTruncate(parentSha, 8), message), + onPress: func() error { + parentNumber := i + 1 + if err := gui.GitCommand.WithSpan(gui.Tr.Spans.RevertCommit).RevertMerge(commit.Sha, parentNumber); err != nil { + return gui.surfaceError(err) + } + return gui.afterRevertCommit() + }, + } } + + return gui.createMenu(gui.Tr.SelectParentCommitForMerge, menuItems, createMenuOptions{showCancel: true}) +} + +func (gui *Gui) afterRevertCommit() error { gui.State.Panels.Commits.SelectedLineIdx++ return gui.refreshSidePanels(refreshOptions{mode: BLOCK_UI, scope: []RefreshableView{COMMITS, BRANCHES}}) } |