vcs: non-modal: Add "Run Commit Checks" action (IDEA-265077)
authorKonstantin Kolosovsky <konstantin.kolosovsky@jetbrains.com>
Mon, 14 Jun 2021 19:58:09 +0000 (22:58 +0300)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Tue, 15 Jun 2021 00:20:01 +0000 (00:20 +0000)
To view commit checks results without actual commit

GitOrigin-RevId: 7adc02da1752ff36dc0fbe30a062a97b457ddcc0

platform/platform-resources-en/src/messages/ActionsBundle.properties
platform/vcs-impl/resources/META-INF/VcsActions.xml
platform/vcs-impl/src/com/intellij/vcs/commit/NonModalCommitWorkflowHandler.kt
platform/vcs-impl/src/com/intellij/vcs/commit/RunCommitChecksExecutor.kt [new file with mode: 0644]

index a551e92edf8bc06267cfa8acf5ae73ac3f553fec..e840e8d4a36869e95ff89700c6cdebb527e46e2f 100644 (file)
@@ -1471,6 +1471,7 @@ action.CommitView.ShowOnDoubleClick.Source.ToolwindowPopup.text=Source
 action.CommitView.SwitchToCommitDialog.text=Switch to Commit Dialog
 action.Vcs.ToggleAmendCommitMode.text=Amend Commit
 action.Vcs.ToggleAmendCommitMode.description=Modify the latest commit of the current branch
+action.Vcs.RunCommitChecks.text=Run Commit Checks
 action.ChangesView.ShowCommitOptions.text=Show Commit Options
 action.Vcs.ApplySelectedChanges.text=Cherry-Pick Selected Changes
 action.Vcs.RevertSelectedChanges.text=Revert Selected Changes
index d07c9171ecb8bec68ac545d086a2d6a47e9c653b..f7d8de8088925abd17d8e253f36ea8408b3fc6e4 100644 (file)
       <reference id="Vcs.MessageActionGroup"/>
     </group>
 
+    <action id="Vcs.RunCommitChecks" class="com.intellij.vcs.commit.RunCommitChecksAction"/>
+
     <action class="com.intellij.openapi.vcs.actions.VcsToolbarLabelAction" id="VcsToolbarLabelAction"/>
 
     <group id="VcsToolbarActions">
       <reference ref="Vcs.ToggleAmendCommitMode"/>
       <reference ref="CheckinProject"/>
       <reference ref="CheckinFiles"/>
+      <reference ref="Vcs.RunCommitChecks"/>
       <reference ref="ChangesView.ShowCommitOptions"/>
       <reference ref="UpdateFiles"/>
       <reference ref="CheckStatusForFiles"/>
index 7c4b35c24125c1cecaa6eb12837cd205ca20c0e9..ec28c83424d85e5544b6bdf31a68eee98428a148 100644 (file)
@@ -77,7 +77,7 @@ abstract class NonModalCommitWorkflowHandler<W : NonModalCommitWorkflow, U : Non
 
   override fun vcsesChanged() {
     initCommitHandlers()
-    workflow.initCommitExecutors(getCommitExecutors(project, workflow.vcses))
+    workflow.initCommitExecutors(getCommitExecutors(project, workflow.vcses) + RunCommitChecksExecutor)
 
     updateDefaultCommitActionEnabled()
     updateDefaultCommitActionName()
@@ -159,14 +159,17 @@ abstract class NonModalCommitWorkflowHandler<W : NonModalCommitWorkflow, U : Non
 
     coroutineScope.launch {
       workflow.executeDefault {
-        if (isSkipCommitChecks()) return@executeDefault ReturnResult.COMMIT
+        val isOnlyRunCommitChecks = commitContext.isOnlyRunCommitChecks
+        commitContext.isOnlyRunCommitChecks = false
+
+        if (isSkipCommitChecks() && !isOnlyRunCommitChecks) return@executeDefault ReturnResult.COMMIT
 
         val indicator = IndeterminateIndicator(ui.commitProgressUi.startProgress())
         indicator.addStateDelegate(object : AbstractProgressIndicatorExBase() {
           override fun cancel() = this@launch.cancel()
         })
         try {
-          runAllHandlers(executor, indicator)
+          runAllHandlers(executor, indicator, isOnlyRunCommitChecks)
         }
         finally {
           indicator.stop()
@@ -177,7 +180,11 @@ abstract class NonModalCommitWorkflowHandler<W : NonModalCommitWorkflow, U : Non
     return true
   }
 
-  private suspend fun runAllHandlers(executor: CommitExecutor?, indicator: ProgressIndicator): ReturnResult {
+  private suspend fun runAllHandlers(
+    executor: CommitExecutor?,
+    indicator: ProgressIndicator,
+    isOnlyRunCommitChecks: Boolean
+  ): ReturnResult {
     workflow.runMetaHandlers(indicator)
     FileDocumentManager.getInstance().saveAllDocuments()
 
@@ -185,8 +192,9 @@ abstract class NonModalCommitWorkflowHandler<W : NonModalCommitWorkflow, U : Non
     if (handlersResult != ReturnResult.COMMIT) return handlersResult
 
     val checksResult = runCommitChecks(indicator)
-    if (checksResult != ReturnResult.COMMIT) isCommitChecksResultUpToDate = true
-    return checksResult
+    if (checksResult != ReturnResult.COMMIT || isOnlyRunCommitChecks) isCommitChecksResultUpToDate = true
+
+    return if (isOnlyRunCommitChecks) ReturnResult.CANCEL else checksResult
   }
 
   private suspend fun runCommitChecks(indicator: ProgressIndicator): ReturnResult {
diff --git a/platform/vcs-impl/src/com/intellij/vcs/commit/RunCommitChecksExecutor.kt b/platform/vcs-impl/src/com/intellij/vcs/commit/RunCommitChecksExecutor.kt
new file mode 100644 (file)
index 0000000..eebc045
--- /dev/null
@@ -0,0 +1,31 @@
+// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+package com.intellij.vcs.commit
+
+import com.intellij.idea.ActionsBundle
+import com.intellij.openapi.util.Key
+import com.intellij.openapi.util.NlsActions
+import com.intellij.openapi.vcs.changes.CommitContext
+import com.intellij.openapi.vcs.changes.CommitExecutor
+import com.intellij.openapi.vcs.changes.CommitSession
+import com.intellij.openapi.vcs.changes.actions.BaseCommitExecutorAction
+
+private val IS_ONLY_RUN_COMMIT_CHECKS_KEY = Key.create<Boolean>("Vcs.Commit.IsOnlyRunCommitChecks")
+internal var CommitContext.isOnlyRunCommitChecks: Boolean by commitProperty(IS_ONLY_RUN_COMMIT_CHECKS_KEY)
+
+internal object RunCommitChecksExecutor : CommitExecutor {
+  const val ID = "Vcs.RunCommitChecks.Executor"
+
+  override fun getId(): String = ID
+
+  override fun getActionText(): @NlsActions.ActionText String = ActionsBundle.message("action.Vcs.RunCommitChecks.text")
+  override fun useDefaultAction(): Boolean = false
+
+  override fun createCommitSession(commitContext: CommitContext): CommitSession {
+    commitContext.isOnlyRunCommitChecks = true
+    return CommitSession.VCS_COMMIT
+  }
+}
+
+internal class RunCommitChecksAction : BaseCommitExecutorAction() {
+  override val executorId: String get() = RunCommitChecksExecutor.ID
+}
\ No newline at end of file