diff --git a/plugins/git4idea/shared/api-dump.txt b/plugins/git4idea/shared/api-dump.txt index 13d6565c4118..ad87d41d54a0 100644 --- a/plugins/git4idea/shared/api-dump.txt +++ b/plugins/git4idea/shared/api-dump.txt @@ -2,6 +2,7 @@ f:com.intellij.vcs.git.GitDisplayName - sf:INSTANCE:com.intellij.vcs.git.GitDisplayName - sf:NAME:java.lang.String - sf:POINTER:java.util.function.Supplier +com.intellij.vcs.git.actions.branch.GitBranchActionToBeWrapped f:com.intellij.vcs.git.ref.GitRefUtil - sf:INSTANCE:com.intellij.vcs.git.ref.GitRefUtil - f:getCommonCurrentBranch(java.util.Collection):git4idea.GitStandardLocalBranch diff --git a/plugins/git4idea/shared/src/com/intellij/vcs/git/actions/branch/GitBranchActionToBeWrapped.kt b/plugins/git4idea/shared/src/com/intellij/vcs/git/actions/branch/GitBranchActionToBeWrapped.kt new file mode 100644 index 000000000000..7340faca776d --- /dev/null +++ b/plugins/git4idea/shared/src/com/intellij/vcs/git/actions/branch/GitBranchActionToBeWrapped.kt @@ -0,0 +1,8 @@ +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.vcs.git.actions.branch + +/** + * A marker interface for branch actions placed in "Git.Branch" group that are created dynamically and need to be + * wrapped in a [GitBranchActionWrapper] to provide proper data context. + */ +interface GitBranchActionToBeWrapped diff --git a/plugins/git4idea/shared/src/com/intellij/vcs/git/actions/branch/GitCheckoutWithUpdateAction.kt b/plugins/git4idea/shared/src/com/intellij/vcs/git/actions/branch/GitCheckoutWithUpdateAction.kt index ef27dd02068d..c21ad28b6405 100644 --- a/plugins/git4idea/shared/src/com/intellij/vcs/git/actions/branch/GitCheckoutWithUpdateAction.kt +++ b/plugins/git4idea/shared/src/com/intellij/vcs/git/actions/branch/GitCheckoutWithUpdateAction.kt @@ -15,7 +15,7 @@ import git4idea.GitStandardLocalBranch import org.jetbrains.annotations.ApiStatus @ApiStatus.Internal -class GitCheckoutWithUpdateAction : DumbAwareAction(), ActionRemoteBehaviorSpecification.FrontendOtherwiseBackend { +class GitCheckoutWithUpdateAction : GitBranchActionToBeWrapped, DumbAwareAction(), ActionRemoteBehaviorSpecification.FrontendOtherwiseBackend { override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT override fun update(e: AnActionEvent) { diff --git a/plugins/git4idea/src/git4idea/actions/ref/GitSingleRefAction.kt b/plugins/git4idea/src/git4idea/actions/ref/GitSingleRefAction.kt index cdc5e5254814..b971e829fb55 100644 --- a/plugins/git4idea/src/git4idea/actions/ref/GitSingleRefAction.kt +++ b/plugins/git4idea/src/git4idea/actions/ref/GitSingleRefAction.kt @@ -9,6 +9,7 @@ import com.intellij.openapi.project.DumbAwareAction import com.intellij.openapi.project.Project import com.intellij.openapi.util.NlsActions import com.intellij.vcs.git.actions.GitSingleRefActions +import com.intellij.vcs.git.actions.branch.GitBranchActionToBeWrapped import git4idea.GitLocalBranch import git4idea.GitReference import git4idea.GitTag @@ -21,7 +22,10 @@ import java.util.function.Supplier import kotlin.reflect.KClass import kotlin.reflect.safeCast -abstract class GitSingleRefAction(dynamicText: Supplier<@NlsActions.ActionText String>) : DumbAwareAction(dynamicText) { +abstract class GitSingleRefAction( + dynamicText: Supplier<@NlsActions.ActionText String> +) : GitBranchActionToBeWrapped, DumbAwareAction(dynamicText) { + @Suppress("UNCHECKED_CAST") protected open val refClass: KClass = GitReference::class as KClass diff --git a/plugins/git4idea/src/git4idea/ui/branch/GitBranchActionWrapper.kt b/plugins/git4idea/src/git4idea/ui/branch/GitBranchActionWrapper.kt index 714e77d5453c..647b91960034 100644 --- a/plugins/git4idea/src/git4idea/ui/branch/GitBranchActionWrapper.kt +++ b/plugins/git4idea/src/git4idea/ui/branch/GitBranchActionWrapper.kt @@ -3,13 +3,13 @@ package git4idea.ui.branch import com.intellij.openapi.actionSystem.* import com.intellij.vcs.git.actions.GitSingleRefActions +import com.intellij.vcs.git.actions.branch.GitBranchActionToBeWrapped import git4idea.GitBranch import git4idea.actions.branch.GitBranchActionsDataKeys -import git4idea.actions.ref.GitSingleRefAction import git4idea.repo.GitRepository internal class GitBranchActionWrapper( - action: GitSingleRefAction<*>, + action: AnAction, private val branch: GitBranch, private val selectedRepository: GitRepository, private val repositories: List, @@ -45,7 +45,7 @@ internal class GitBranchActionWrapper( repositories: List, ) { when (action) { - is GitSingleRefAction<*> -> result.add(GitBranchActionWrapper(action, branch, selectedRepository, repositories)) + is GitBranchActionToBeWrapped -> result.add(GitBranchActionWrapper(action, branch, selectedRepository, repositories)) is ActionGroup -> { action.getChildren(e).forEach { doWrapActions(result, e, it, branch, selectedRepository, repositories)