From 789cbf510244b33829d33231890bd363579b19e8 Mon Sep 17 00:00:00 2001 From: Dmitry Zhuravlev Date: Fri, 13 Dec 2019 20:15:00 +0300 Subject: [PATCH] git: hide update action if no remotes even configured The same behavior already exist in fetch action GitOrigin-RevId: 027a180df51f2490e2f23595635ac7c2fe095f95 --- .../src/git4idea/ui/branch/GitBranchActionsUtil.kt | 6 +++++- .../git4idea/ui/branch/GitBranchPopupActions.java | 5 +++++ .../branch/dashboard/BranchesDashboardActions.kt | 14 ++++++++++---- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/plugins/git4idea/src/git4idea/ui/branch/GitBranchActionsUtil.kt b/plugins/git4idea/src/git4idea/ui/branch/GitBranchActionsUtil.kt index 1cb0c7be4ebc..273260c72f63 100644 --- a/plugins/git4idea/src/git4idea/ui/branch/GitBranchActionsUtil.kt +++ b/plugins/git4idea/src/git4idea/ui/branch/GitBranchActionsUtil.kt @@ -2,13 +2,13 @@ package git4idea.ui.branch import com.intellij.openapi.diagnostic.Logger -import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.progress.ProgressIndicator import com.intellij.openapi.progress.ProgressManager import com.intellij.openapi.progress.Task import com.intellij.openapi.project.Project import com.intellij.openapi.vcs.VcsException import com.intellij.openapi.vcs.VcsNotifier +import git4idea.GitUtil import git4idea.GitVcs import git4idea.branch.GitBrancher import git4idea.branch.GitNewBranchDialog @@ -159,3 +159,7 @@ internal fun isTrackingInfosExist(branchNames: List, repositories: List< repositories .flatMap(GitRepository::getBranchTrackInfos) .any { trackingBranchInfo -> branchNames.any { branchName -> branchName == trackingBranchInfo.localBranch.name } } + +internal fun hasRemotes(project: Project): Boolean { + return GitUtil.getRepositories(project).any { repository -> !repository.remotes.isEmpty() } +} diff --git a/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopupActions.java b/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopupActions.java index 75cd93b967bc..6181332b0830 100644 --- a/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopupActions.java +++ b/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopupActions.java @@ -793,6 +793,11 @@ public class GitBranchPopupActions { @Override public void update(@NotNull AnActionEvent e) { Presentation presentation = e.getPresentation(); + Project project = e.getProject(); + if (project == null || !hasRemotes(project)) { + presentation.setEnabledAndVisible(false); + return; + } String branchPresentation = getBranchPresentation(myBranchName); String description = String.format("Fetch remote tracking branch and fast-forward %s (like `git fetch %s:%s`)", branchPresentation, myBranchName, myBranchName); diff --git a/plugins/git4idea/src/git4idea/ui/branch/dashboard/BranchesDashboardActions.kt b/plugins/git4idea/src/git4idea/ui/branch/dashboard/BranchesDashboardActions.kt index 550120b338ac..240b0a294aac 100644 --- a/plugins/git4idea/src/git4idea/ui/branch/dashboard/BranchesDashboardActions.kt +++ b/plugins/git4idea/src/git4idea/ui/branch/dashboard/BranchesDashboardActions.kt @@ -21,10 +21,7 @@ import git4idea.fetch.GitFetchSupport import git4idea.isRemoteBranchProtected import git4idea.repo.GitRepository import git4idea.repo.GitRepositoryManager -import git4idea.ui.branch.GitBranchPopupActions -import git4idea.ui.branch.createOrCheckoutNewBranch -import git4idea.ui.branch.isTrackingInfosExist -import git4idea.ui.branch.updateBranches +import git4idea.ui.branch.* import javax.swing.Icon internal object BranchesDashboardActions { @@ -116,6 +113,15 @@ internal object BranchesDashboardActions { } class UpdateSelectedBranchAction : BranchesActionBase(text = "Update Selected", icon = AllIcons.Actions.CheckOut) { + override fun update(e: AnActionEvent) { + val enabledAndVisible = e.project?.let(::hasRemotes) ?: false + e.presentation.isEnabledAndVisible = enabledAndVisible + + if (enabledAndVisible) { + super.update(e) + } + } + override fun update(e: AnActionEvent, project: Project, branches: Collection) { val presentation = e.presentation if (GitFetchSupport.fetchSupport(project).isFetchRunning) {