From 8416dfd071ff8c3484467d1bc1dd583fac112323 Mon Sep 17 00:00:00 2001 From: Stanislau Palyn Date: Mon, 3 Nov 2025 08:59:05 +0100 Subject: [PATCH] [git] IJPL-73967 Disable the Checkout and Update action when there is no tracked branch while keeping it visible To be consistent with the Update action. Previously it was not visible in that case. GitOrigin-RevId: 4b05d8683369907e92be31455538d5cbd9b355ea --- .../branch/GitCheckoutWithUpdateAction.kt | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) 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 c21ad28b6405..f7249b1783dc 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 @@ -12,6 +12,7 @@ import com.intellij.vcs.git.branch.popup.GitBranchesPopupKeys import com.intellij.vcs.git.repo.GitRepositoryModel import com.intellij.vcs.git.rpc.GitOperationsApi import git4idea.GitStandardLocalBranch +import git4idea.i18n.GitBundle import org.jetbrains.annotations.ApiStatus @ApiStatus.Internal @@ -19,11 +20,24 @@ class GitCheckoutWithUpdateAction : GitBranchActionToBeWrapped, DumbAwareAction( override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT override fun update(e: AnActionEvent) { - e.presentation.isEnabledAndVisible = ActionData.create(e) != null + val data = ActionData.create(e) + with(e.presentation) { + if (data == null) { + isEnabledAndVisible = false + return + } + isEnabledAndVisible = true + isEnabled = data.hasTrackingInfos + if (!data.hasTrackingInfos) { + description = GitBundle.message("branches.tracking.branch.doesn.t.configured.for.s", + "'${data.branch.name}'") + } + } } override fun actionPerformed(e: AnActionEvent) { val data = ActionData.create(e) ?: return + if (!data.hasTrackingInfos) return val repositoryIds = data.repositories.map { it.repositoryId } GitOperationsApi.launchRequest(data.project) { @@ -35,6 +49,7 @@ class GitCheckoutWithUpdateAction : GitBranchActionToBeWrapped, DumbAwareAction( val project: Project, val branch: GitStandardLocalBranch, val repositories: List, + val hasTrackingInfos: Boolean, ) { companion object { fun create(e: AnActionEvent): ActionData? { @@ -47,8 +62,7 @@ class GitCheckoutWithUpdateAction : GitBranchActionToBeWrapped, DumbAwareAction( return when { !hasRemotes(repositories) -> null isAlreadyCheckedOut(repositories, branch) -> null - !hasTrackingInfos(repositories, branch) -> null - else -> ActionData(project, branch, repositories) + else -> ActionData(project, branch, repositories, hasTrackingInfos = hasTrackingInfos(repositories, branch)) } }