diff --git a/plugins/git4idea/src/git4idea/actions/workingTree/ShowWorkingTreesAction.kt b/plugins/git4idea/src/git4idea/actions/workingTree/ShowWorkingTreesAction.kt index db6ee092b07f..34db1df46bcb 100644 --- a/plugins/git4idea/src/git4idea/actions/workingTree/ShowWorkingTreesAction.kt +++ b/plugins/git4idea/src/git4idea/actions/workingTree/ShowWorkingTreesAction.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package git4idea.actions.workingTree import com.intellij.openapi.actionSystem.ActionUpdateThread @@ -21,9 +21,8 @@ internal class ShowWorkingTreesAction : DumbAwareAction() { private fun shouldShow(e: AnActionEvent): Boolean { val project = e.project ?: return false - if (!GitWorkingTreesUtil.isWorkingTreesFeatureEnabled()) return false if (ToolWindowManager.getInstance(project).getToolWindow(ChangesViewContentManager.TOOLWINDOW_ID) == null) return false - return GitWorkingTreesService.getInstance(project).getSingleRepositoryInProjectRootOrNull() != null + return GitWorkingTreesService.getSingleRepositoryOrNullIfEnabled(project) != null } override fun actionPerformed(e: AnActionEvent) { diff --git a/plugins/git4idea/src/git4idea/workingTrees/GitWorkingTreesService.kt b/plugins/git4idea/src/git4idea/workingTrees/GitWorkingTreesService.kt index ba443f299ea2..0b7bb6d11e7f 100644 --- a/plugins/git4idea/src/git4idea/workingTrees/GitWorkingTreesService.kt +++ b/plugins/git4idea/src/git4idea/workingTrees/GitWorkingTreesService.kt @@ -3,9 +3,7 @@ package git4idea.workingTrees import com.intellij.ide.util.PropertiesComponent import com.intellij.openapi.components.Service -import com.intellij.openapi.project.BaseProjectDirectories.Companion.getBaseDirectories import com.intellij.openapi.project.Project -import com.intellij.openapi.vfs.VirtualFile import git4idea.repo.GitRepository import git4idea.repo.GitRepositoryManager import kotlinx.coroutines.CoroutineScope @@ -17,34 +15,20 @@ internal class GitWorkingTreesService(private val project: Project, val coroutin private const val WORKING_TREE_TAB_CLOSED_BY_USER_PROPERTY: String = "Git.Working.Tree.Tab.closed.by.user" fun getInstance(project: Project): GitWorkingTreesService = project.getService(GitWorkingTreesService::class.java) - } - /** - * So far only the case `single repository in project root` is supported for working trees - */ - fun getSingleRepositoryInProjectRootOrNull(): GitRepository? { - val projectRoot = getOnlyProjectRootOrNull() - if (projectRoot == null) { - return null + /** + * So far only the `single repository` case is supported for working trees + */ + fun getSingleRepositoryOrNullIfEnabled(project: Project?): GitRepository? { + if (project == null) return null + if (!GitWorkingTreesUtil.isWorkingTreesFeatureEnabled()) return null + val repositories = GitRepositoryManager.getInstance(project).repositories + return repositories.singleOrNull() } - val repositories = GitRepositoryManager.getInstance(project).repositories - val repository = repositories.singleOrNull() ?: return null - if (projectRoot != repository.root) { - return null - } - return repository - } - - private fun getOnlyProjectRootOrNull(): VirtualFile? { - val baseDirectories = project.getBaseDirectories() - return baseDirectories.singleOrNull() } fun shouldWorkingTreesTabBeShown(): Boolean { - if (!GitWorkingTreesUtil.isWorkingTreesFeatureEnabled()) { - return false - } - if (getSingleRepositoryInProjectRootOrNull() == null) { + if (getSingleRepositoryOrNullIfEnabled(project) == null) { return false } return !PropertiesComponent.getInstance(project).getBoolean(WORKING_TREE_TAB_CLOSED_BY_USER_PROPERTY, false) diff --git a/plugins/git4idea/src/git4idea/workingTrees/ui/GitWorkingTreesContentProvider.kt b/plugins/git4idea/src/git4idea/workingTrees/ui/GitWorkingTreesContentProvider.kt index 6e9b58a9ffa1..a67ec3b38a33 100644 --- a/plugins/git4idea/src/git4idea/workingTrees/ui/GitWorkingTreesContentProvider.kt +++ b/plugins/git4idea/src/git4idea/workingTrees/ui/GitWorkingTreesContentProvider.kt @@ -103,7 +103,7 @@ internal class GitWorkingTreesContentProvider(private val project: Project) : Ch fun reload(project: Project) { clear() - val currentRepository = GitWorkingTreesService.getInstance(project).getSingleRepositoryInProjectRootOrNull() + val currentRepository = GitWorkingTreesService.getSingleRepositoryOrNullIfEnabled(project) repository = currentRepository val workingTrees = currentRepository?.workingTreeHolder?.getWorkingTrees() if (workingTrees != null && workingTrees.size > 1) {