From 63e358d9c8443a5db889ae13aa168f3ce9b67fdb Mon Sep 17 00:00:00 2001 From: Shautvast Date: Mon, 29 Sep 2025 20:10:13 +0200 Subject: [PATCH] clean up the mess --- .../autoprefixcommit/APCProjectActivity.kt | 2 +- .../AlternativeBranchNameHandler.kt | 35 -------------- .../BranchNameCheckinHandler.kt | 2 +- .../BranchNameCommitMessageProvider.kt | 19 -------- .../DelayedBranchNameHandler.kt | 47 ------------------- 5 files changed, 2 insertions(+), 103 deletions(-) delete mode 100644 src/main/kotlin/nl/topsquad/autoprefixcommit/AlternativeBranchNameHandler.kt delete mode 100644 src/main/kotlin/nl/topsquad/autoprefixcommit/BranchNameCommitMessageProvider.kt delete mode 100644 src/main/kotlin/nl/topsquad/autoprefixcommit/DelayedBranchNameHandler.kt diff --git a/src/main/kotlin/nl/topsquad/autoprefixcommit/APCProjectActivity.kt b/src/main/kotlin/nl/topsquad/autoprefixcommit/APCProjectActivity.kt index 5c156a4..a7d9db4 100644 --- a/src/main/kotlin/nl/topsquad/autoprefixcommit/APCProjectActivity.kt +++ b/src/main/kotlin/nl/topsquad/autoprefixcommit/APCProjectActivity.kt @@ -7,6 +7,6 @@ import com.intellij.openapi.startup.ProjectActivity class APCProjectActivity: ProjectActivity { override suspend fun execute(project : Project){ - thisLogger().warn("Autoprefixer Commit is active") + thisLogger().warn("Autoprefix-commit plugin is active") } } \ No newline at end of file diff --git a/src/main/kotlin/nl/topsquad/autoprefixcommit/AlternativeBranchNameHandler.kt b/src/main/kotlin/nl/topsquad/autoprefixcommit/AlternativeBranchNameHandler.kt deleted file mode 100644 index f55f1fd..0000000 --- a/src/main/kotlin/nl/topsquad/autoprefixcommit/AlternativeBranchNameHandler.kt +++ /dev/null @@ -1,35 +0,0 @@ -package nl.topsquad.autoprefixcommit - -import com.intellij.openapi.vcs.CheckinProjectPanel -import com.intellij.openapi.vcs.changes.CommitContext -import com.intellij.openapi.vcs.checkin.CheckinHandler -import com.intellij.openapi.vcs.checkin.CheckinHandlerFactory -import git4idea.repo.GitRepositoryManager - -/** - * Alternative implementation that modifies the commit message right before commit - */ -class AlternativeBranchNameHandlerFactory : CheckinHandlerFactory() { - override fun createHandler(panel: CheckinProjectPanel, commitContext: CommitContext): CheckinHandler { - return object : CheckinHandler() { - - override fun beforeCheckin(): ReturnResult { - val repository = GitRepositoryManager.getInstance(panel.project).repositories.firstOrNull() - repository?.let { - val currentBranch = it.currentBranchName - val currentMessage = panel.commitMessage - - if (currentBranch != null && !currentMessage.contains(currentBranch)) { - val newMessage = if (currentMessage.isEmpty()) { - "$currentBranch: " - } else { - "$currentBranch: $currentMessage" - } - panel.commitMessage = newMessage - } - } - return ReturnResult.COMMIT - } - } - } -} diff --git a/src/main/kotlin/nl/topsquad/autoprefixcommit/BranchNameCheckinHandler.kt b/src/main/kotlin/nl/topsquad/autoprefixcommit/BranchNameCheckinHandler.kt index 46f841f..e8f957e 100644 --- a/src/main/kotlin/nl/topsquad/autoprefixcommit/BranchNameCheckinHandler.kt +++ b/src/main/kotlin/nl/topsquad/autoprefixcommit/BranchNameCheckinHandler.kt @@ -28,7 +28,7 @@ class BranchNameCheckinHandlerFactory : CheckinHandlerFactory() { val repository = GitRepositoryManager.getInstance(panel.project).repositories.firstOrNull() return repository?.let { - val branchName = it.currentBranchName; + val branchName = it.currentBranchName if (branchName != null && !message.startsWith("${branchName} ")) { "${it.currentBranchName ?: ""} ${message} " } else { diff --git a/src/main/kotlin/nl/topsquad/autoprefixcommit/BranchNameCommitMessageProvider.kt b/src/main/kotlin/nl/topsquad/autoprefixcommit/BranchNameCommitMessageProvider.kt deleted file mode 100644 index fae9463..0000000 --- a/src/main/kotlin/nl/topsquad/autoprefixcommit/BranchNameCommitMessageProvider.kt +++ /dev/null @@ -1,19 +0,0 @@ -package nl.topsquad.autoprefixcommit - -import com.intellij.openapi.project.Project -import com.intellij.openapi.vcs.changes.LocalChangeList -import com.intellij.openapi.vcs.changes.ui.CommitMessageProvider -import com.intellij.util.diff.Diff -import git4idea.repo.GitRepositoryManager -import org.jetbrains.annotations.NotNull - -class BranchNameCommitMessageProvider: CommitMessageProvider { - override fun getCommitMessage(@NotNull forChangelist: LocalChangeList, project: Project): String? { - val repository = GitRepositoryManager.getInstance(project).repositories.firstOrNull() - repository?.let { - val currentBranch = it.currentBranchName - return currentBranch - } - return "" - } -} \ No newline at end of file diff --git a/src/main/kotlin/nl/topsquad/autoprefixcommit/DelayedBranchNameHandler.kt b/src/main/kotlin/nl/topsquad/autoprefixcommit/DelayedBranchNameHandler.kt deleted file mode 100644 index 1fb2927..0000000 --- a/src/main/kotlin/nl/topsquad/autoprefixcommit/DelayedBranchNameHandler.kt +++ /dev/null @@ -1,47 +0,0 @@ -package nl.topsquad.autoprefixcommit - -import com.intellij.openapi.application.ApplicationManager -import com.intellij.openapi.vcs.CheckinProjectPanel -import com.intellij.openapi.vcs.changes.CommitContext -import com.intellij.openapi.vcs.checkin.CheckinHandler -import com.intellij.openapi.vcs.checkin.CheckinHandlerFactory -import git4idea.repo.GitRepositoryManager -import javax.swing.Timer - -/** - * Implementation that uses a timer to delay commit message modification - */ -class DelayedBranchNameHandlerFactory : CheckinHandlerFactory() { - override fun createHandler(panel: CheckinProjectPanel, commitContext: CommitContext): CheckinHandler { - return object : CheckinHandler() { - - init { - // Use a timer to delay the modification slightly - val timer = Timer(100) { // 100ms delay - ApplicationManager.getApplication().invokeLater { - modifyCommitMessage(panel) - } - } - timer.isRepeats = false - timer.start() - } - - private fun modifyCommitMessage(panel: CheckinProjectPanel) { - val repository = GitRepositoryManager.getInstance(panel.project).repositories.firstOrNull() - repository?.let { - val currentBranch = it.currentBranchName - val currentMessage = panel.commitMessage - - if (currentBranch != null && !currentMessage.contains(currentBranch)) { - val newMessage = if (currentMessage.isEmpty()) { - "$currentBranch: " - } else { - "$currentBranch: $currentMessage" - } - panel.commitMessage = newMessage - } - } - } - } - } -}