From dfa6a7263c88cb5fa623adb87b8df140e5bc6fcd Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Tue, 29 Aug 2017 22:21:37 +0300 Subject: [PATCH] Let reword the latest commit during rebase Rebase during rebase is not possible, but the latest commit is reworded via amend, therefore can be allowed. --- .../git4idea/src/git4idea/rebase/GitCommitEditingAction.kt | 7 ++++++- plugins/git4idea/src/git4idea/rebase/GitRewordAction.kt | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/git4idea/src/git4idea/rebase/GitCommitEditingAction.kt b/plugins/git4idea/src/git4idea/rebase/GitCommitEditingAction.kt index 26c3c9e1e34a..912b6315601a 100644 --- a/plugins/git4idea/src/git4idea/rebase/GitCommitEditingAction.kt +++ b/plugins/git4idea/src/git4idea/rebase/GitCommitEditingAction.kt @@ -137,10 +137,11 @@ abstract class GitCommitEditingAction : DumbAwareAction() { private fun commitPushedToProtectedBranchError(protectedBranch: String) = "The commit is already pushed to protected branch '$protectedBranch'" - protected fun prohibitRebaseDuringRebase(e: AnActionEvent, operation: String) { + protected fun prohibitRebaseDuringRebase(e: AnActionEvent, operation: String, allowRebaseIfHeadCommit: Boolean = false) { if (e.presentation.isEnabledAndVisible) { val state = getRepository(e).state if (state == NORMAL || state == DETACHED) return + if (state == REBASING && allowRebaseIfHeadCommit && isHeadCommit(e)) return e.presentation.isEnabled = false e.presentation.description = when (state) { @@ -153,4 +154,8 @@ abstract class GitCommitEditingAction : DumbAwareAction() { } } } + + protected fun isHeadCommit(e: AnActionEvent): Boolean { + return getSelectedCommit(e).id.asString() == getRepository(e).currentRevision + } } diff --git a/plugins/git4idea/src/git4idea/rebase/GitRewordAction.kt b/plugins/git4idea/src/git4idea/rebase/GitRewordAction.kt index 40bee0d79565..8c5830661af7 100644 --- a/plugins/git4idea/src/git4idea/rebase/GitRewordAction.kt +++ b/plugins/git4idea/src/git4idea/rebase/GitRewordAction.kt @@ -45,7 +45,7 @@ class GitRewordAction : GitCommitEditingAction() { override fun update(e: AnActionEvent) { super.update(e) - prohibitRebaseDuringRebase(e, "reword") + prohibitRebaseDuringRebase(e, "reword", true) } override fun actionPerformed(e: AnActionEvent) {