diff --git a/plugins/git4idea/src/git4idea/actions/workingTree/GitWorkingTreeActionsDataKeys.kt b/plugins/git4idea/src/git4idea/actions/workingTree/GitWorkingTreeTabActionsDataKeys.kt similarity index 51% rename from plugins/git4idea/src/git4idea/actions/workingTree/GitWorkingTreeActionsDataKeys.kt rename to plugins/git4idea/src/git4idea/actions/workingTree/GitWorkingTreeTabActionsDataKeys.kt index b0401c533928..3fb7d62ca60f 100644 --- a/plugins/git4idea/src/git4idea/actions/workingTree/GitWorkingTreeActionsDataKeys.kt +++ b/plugins/git4idea/src/git4idea/actions/workingTree/GitWorkingTreeTabActionsDataKeys.kt @@ -1,16 +1,16 @@ -// 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.DataKey -import com.intellij.platform.vcs.impl.shared.RepositoryId import git4idea.GitWorkingTree +import git4idea.repo.GitRepository import org.jetbrains.annotations.ApiStatus @ApiStatus.Internal -object GitWorkingTreeActionsDataKeys { +object GitWorkingTreeTabActionsDataKeys { @JvmField - val SELECTED_WORKING_TREES: DataKey> = DataKey.create("SELECTED_GIT_WORKING_TREE") + val SELECTED_WORKING_TREES: DataKey> = DataKey.create("SELECTED_GIT_WORKING_TREE_IN_WORKING_TREE_TAB") @JvmField - val GIT_REPOSITORY_MODEL_ID: DataKey = DataKey.create("GIT_REPOSITORY_MODEL_ID") + val CURRENT_REPOSITORY: DataKey = DataKey.create("CURRENT_REPOSITORY_IN_WORKING_TREE_TAB") } diff --git a/plugins/git4idea/src/git4idea/workingTrees/GitWorkingTreesService.kt b/plugins/git4idea/src/git4idea/workingTrees/GitWorkingTreesService.kt index e56d8d192c70..ba443f299ea2 100644 --- a/plugins/git4idea/src/git4idea/workingTrees/GitWorkingTreesService.kt +++ b/plugins/git4idea/src/git4idea/workingTrees/GitWorkingTreesService.kt @@ -1,13 +1,12 @@ -// 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.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.platform.vcs.impl.shared.RepositoryId -import com.intellij.vcs.git.repo.GitRepositoriesHolder -import com.intellij.vcs.git.repo.GitRepositoryModel +import com.intellij.openapi.vfs.VirtualFile +import git4idea.repo.GitRepository import git4idea.repo.GitRepositoryManager import kotlinx.coroutines.CoroutineScope @@ -23,30 +22,22 @@ internal class GitWorkingTreesService(private val project: Project, val coroutin /** * So far only the case `single repository in project root` is supported for working trees */ - fun getSingleRepositoryInProjectRootOrNull(): GitRepositoryModel? { - val baseDirectories = project.getBaseDirectories() - if (baseDirectories.size != 1) { + fun getSingleRepositoryInProjectRootOrNull(): GitRepository? { + val projectRoot = getOnlyProjectRootOrNull() + if (projectRoot == null) { return null } - val projectRoot = baseDirectories.first() - val holder = GitRepositoriesHolder.getInstance(project) - if (!holder.initialized) { - return null - } - val repositoryModels = holder.getAll() - if (repositoryModels.isEmpty()) { - return null - } - if (repositoryModels.size > 1) { + val repositories = GitRepositoryManager.getInstance(project).repositories + val repository = repositories.singleOrNull() ?: return null + if (projectRoot != repository.root) { return null } + return repository + } - val model = repositoryModels[0] - val modelRoot = model.root.virtualFile ?: return null - if (modelRoot != projectRoot) { - return null - } - return model + private fun getOnlyProjectRootOrNull(): VirtualFile? { + val baseDirectories = project.getBaseDirectories() + return baseDirectories.singleOrNull() } fun shouldWorkingTreesTabBeShown(): Boolean { @@ -66,10 +57,4 @@ internal class GitWorkingTreesService(private val project: Project, val coroutin fun workingTreesTabClosedByUser() { PropertiesComponent.getInstance(project).setValue(WORKING_TREE_TAB_CLOSED_BY_USER_PROPERTY, true) } - - fun reloadRepository(repositoryId: RepositoryId) { - val repositoryModel = GitRepositoriesHolder.getInstance(project).get(repositoryId) ?: return - val repository = GitRepositoryManager.getInstance(project).getRepositoryForFile(repositoryModel.root) ?: return - repository.workingTreeHolder.reload() - } } \ No newline at end of file diff --git a/plugins/git4idea/src/git4idea/workingTrees/ui/GitWorkingTreesContentProvider.kt b/plugins/git4idea/src/git4idea/workingTrees/ui/GitWorkingTreesContentProvider.kt index 838915feb44f..6e9b58a9ffa1 100644 --- a/plugins/git4idea/src/git4idea/workingTrees/ui/GitWorkingTreesContentProvider.kt +++ b/plugins/git4idea/src/git4idea/workingTrees/ui/GitWorkingTreesContentProvider.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.workingTrees.ui import com.intellij.icons.AllIcons @@ -23,10 +23,10 @@ import com.intellij.ui.content.ContentManagerEvent import com.intellij.ui.content.ContentManagerListener import com.intellij.util.ui.components.BorderLayoutPanel import com.intellij.vcs.git.repo.GitRepositoriesHolder -import com.intellij.vcs.git.repo.GitRepositoryModel import git4idea.GitWorkingTree -import git4idea.actions.workingTree.GitWorkingTreeActionsDataKeys +import git4idea.actions.workingTree.GitWorkingTreeTabActionsDataKeys import git4idea.i18n.GitBundle +import git4idea.repo.GitRepository import git4idea.workingTrees.GitWorkingTreesService import java.awt.Component import java.awt.Point @@ -88,13 +88,13 @@ internal class GitWorkingTreesContentProvider(private val project: Project) : Ch } override fun uiDataSnapshot(sink: DataSink) { - sink[GitWorkingTreeActionsDataKeys.SELECTED_WORKING_TREES] = list.selectedValuesList - sink[GitWorkingTreeActionsDataKeys.GIT_REPOSITORY_MODEL_ID] = model.repository?.repositoryId + sink[GitWorkingTreeTabActionsDataKeys.SELECTED_WORKING_TREES] = list.selectedValuesList + sink[GitWorkingTreeTabActionsDataKeys.CURRENT_REPOSITORY] = model.repository } } private class WorkingTreesListModel(project: Project) : DefaultListModel() { - var repository: GitRepositoryModel? = null + var repository: GitRepository? = null private set init { @@ -105,7 +105,7 @@ internal class GitWorkingTreesContentProvider(private val project: Project) : Ch clear() val currentRepository = GitWorkingTreesService.getInstance(project).getSingleRepositoryInProjectRootOrNull() repository = currentRepository - val workingTrees = currentRepository?.state?.workingTrees + val workingTrees = currentRepository?.workingTreeHolder?.getWorkingTrees() if (workingTrees != null && workingTrees.size > 1) { workingTrees.forEach { if (it.isMain) { diff --git a/plugins/git4idea/src/git4idea/workingTrees/ui/OpenWorkingTreeAction.kt b/plugins/git4idea/src/git4idea/workingTrees/ui/OpenWorkingTreeAction.kt index bf0fd736c059..776b53318acf 100644 --- a/plugins/git4idea/src/git4idea/workingTrees/ui/OpenWorkingTreeAction.kt +++ b/plugins/git4idea/src/git4idea/workingTrees/ui/OpenWorkingTreeAction.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.workingTrees.ui import com.intellij.ide.impl.OpenProjectTask @@ -9,7 +9,7 @@ import com.intellij.openapi.project.Project import com.intellij.openapi.project.ProjectManager import com.intellij.platform.PlatformProjectOpenProcessor import git4idea.GitWorkingTree -import git4idea.actions.workingTree.GitWorkingTreeActionsDataKeys.SELECTED_WORKING_TREES +import git4idea.actions.workingTree.GitWorkingTreeTabActionsDataKeys.SELECTED_WORKING_TREES import git4idea.workingTrees.GitWorkingTreesService import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch diff --git a/plugins/git4idea/src/git4idea/workingTrees/ui/RemoveWorkingTreeAction.kt b/plugins/git4idea/src/git4idea/workingTrees/ui/RemoveWorkingTreeAction.kt index 91ff125fd97e..65d295f11645 100644 --- a/plugins/git4idea/src/git4idea/workingTrees/ui/RemoveWorkingTreeAction.kt +++ b/plugins/git4idea/src/git4idea/workingTrees/ui/RemoveWorkingTreeAction.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.workingTrees.ui import com.intellij.CommonBundle @@ -11,12 +11,12 @@ import com.intellij.openapi.project.Project import com.intellij.openapi.ui.Messages import com.intellij.openapi.vcs.VcsNotifier import com.intellij.platform.ide.progress.withBackgroundProgress -import com.intellij.platform.vcs.impl.shared.RepositoryId import git4idea.GitNotificationIdsHolder import git4idea.GitWorkingTree -import git4idea.actions.workingTree.GitWorkingTreeActionsDataKeys -import git4idea.actions.workingTree.GitWorkingTreeActionsDataKeys.SELECTED_WORKING_TREES +import git4idea.actions.workingTree.GitWorkingTreeTabActionsDataKeys +import git4idea.actions.workingTree.GitWorkingTreeTabActionsDataKeys.SELECTED_WORKING_TREES import git4idea.i18n.GitBundle +import git4idea.repo.GitRepository import git4idea.workingTrees.GitWorkingTreesCommandService import git4idea.workingTrees.GitWorkingTreesService import kotlinx.coroutines.Dispatchers @@ -31,19 +31,19 @@ internal class RemoveWorkingTreeAction : DumbAwareAction() { override fun update(e: AnActionEvent) { super.update(e) val data = e.getData(SELECTED_WORKING_TREES) - val repositoryId = e.getData(GitWorkingTreeActionsDataKeys.GIT_REPOSITORY_MODEL_ID) - e.presentation.isEnabled = isEnabledFor(data, e.project, repositoryId) + val repository = e.getData(GitWorkingTreeTabActionsDataKeys.CURRENT_REPOSITORY) + e.presentation.isEnabled = isEnabledFor(data, e.project, repository) } - private fun isEnabledFor(trees: List?, project: Project?, repository: RepositoryId?): Boolean { + private fun isEnabledFor(trees: List?, project: Project?, repository: GitRepository?): Boolean { return project != null && repository != null && !trees.isNullOrEmpty() && trees.all { !it.isCurrent && !it.isMain } } override fun actionPerformed(e: AnActionEvent) { val project = e.project ?: return val data = e.getData(SELECTED_WORKING_TREES) - val repositoryId = e.getData(GitWorkingTreeActionsDataKeys.GIT_REPOSITORY_MODEL_ID) - if (!isEnabledFor(data, project, repositoryId)) return + val repository = e.getData(GitWorkingTreeTabActionsDataKeys.CURRENT_REPOSITORY) + if (!isEnabledFor(data, project, repository)) return val result = if (data!!.size == 1) { val tree = data.first() @@ -64,17 +64,17 @@ internal class RemoveWorkingTreeAction : DumbAwareAction() { if (result != Messages.YES) return GitWorkingTreesService.getInstance(project).coroutineScope.launch(Dispatchers.IO) { for (tree in data) { - delete(project, tree, repositoryId!!) + delete(project, tree, repository!!) } } } - private suspend fun delete(project: Project, tree: GitWorkingTree, repositoryId: RepositoryId) { + private suspend fun delete(project: Project, tree: GitWorkingTree, repository: GitRepository) { val commandResult = withBackgroundProgress(project, GitBundle.message("progress.title.deleting.worktree"), cancellable = true) { service().deleteWorkingTree(project, tree) } if (commandResult.success()) { - GitWorkingTreesService.getInstance(project).reloadRepository(repositoryId) + repository.workingTreeHolder.reload() VcsNotifier.getInstance(project).notifySuccess(GitNotificationIdsHolder.WORKING_TREE_DELETED, "", GitBundle.message("Git.WorkingTrees.delete.worktree.success.message", tree.path.presentableUrl))