mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[git] IJPL-211607 IJPL-204771 Support only single repo case IJ-MR-185641
GitOrigin-RevId: 748e7ed3154903765fb8dac27ff14e9b69e6075f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a547d21d56
commit
258afe3f84
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user