diff --git a/plugins/git4idea/src/git4idea/GitRootConverter.java b/plugins/git4idea/src/git4idea/GitRootConverter.java index 1e29fde47f51..0250524bcaf5 100644 --- a/plugins/git4idea/src/git4idea/GitRootConverter.java +++ b/plugins/git4idea/src/git4idea/GitRootConverter.java @@ -16,13 +16,9 @@ package git4idea; -import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.AbstractVcs; -import com.intellij.openapi.vcs.VcsDirectoryMapping; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.containers.HashSet; -import git4idea.roots.GitRootDetectInfo; -import git4idea.roots.GitRootDetector; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -33,23 +29,12 @@ import java.util.List; */ public class GitRootConverter implements AbstractVcs.RootsConvertor { - @NotNull private final Project myProject; - @NotNull private final PlatformFacade myPlatformFacade; - - public GitRootConverter(@NotNull Project project, @NotNull PlatformFacade facade) { - myProject = project; - myPlatformFacade = facade; - } + public static final GitRootConverter INSTANCE = new GitRootConverter(); @NotNull public List convertRoots(@NotNull List result) { - GitRootDetectInfo detectInfo = new GitRootDetector(myProject, myPlatformFacade).detect(); - + // TODO this should be faster, because it is called rather often. gitRootOrNull could be a bottle-neck. ArrayList roots = new ArrayList(); - if (hasProjectMapping()) { - roots.addAll(detectInfo.getRoots()); - } - HashSet listed = new HashSet(); for (VirtualFile f : result) { VirtualFile r = GitUtil.gitRootOrNull(f); @@ -59,14 +44,4 @@ public class GitRootConverter implements AbstractVcs.RootsConvertor { } return roots; } - - private boolean hasProjectMapping() { - for (VcsDirectoryMapping mapping : myPlatformFacade.getVcsManager(myProject).getDirectoryMappings()) { - if (mapping.isDefaultMapping()) { - return true; - } - } - return false; - } - } diff --git a/plugins/git4idea/src/git4idea/GitVcs.java b/plugins/git4idea/src/git4idea/GitVcs.java index 6f4e778b7655..8bee54c341f3 100644 --- a/plugins/git4idea/src/git4idea/GitVcs.java +++ b/plugins/git4idea/src/git4idea/GitVcs.java @@ -135,7 +135,6 @@ public class GitVcs extends AbstractVcs { private GitBranchWidget myBranchWidget; private GitVersion myVersion = GitVersion.NULL; // version of Git which this plugin uses. - private final GitRootConverter myRootConverter; @Nullable public static GitVcs getInstance(Project project) { @@ -175,7 +174,6 @@ public class GitVcs extends AbstractVcs { myTaskQueue = new BackgroundTaskQueue(myProject, GitBundle.getString("task.queue.title")); myExecutableValidator = new GitExecutableValidator(myProject, this); myPlatformFacade = ServiceManager.getService(myProject, PlatformFacade.class); - myRootConverter = new GitRootConverter(myProject, myPlatformFacade); } @@ -497,7 +495,7 @@ public class GitVcs extends AbstractVcs { @Override public RootsConvertor getCustomConvertor() { - return myRootConverter; + return GitRootConverter.INSTANCE; } public static VcsKey getKey() { diff --git a/plugins/git4idea/src/git4idea/roots/GitRootErrorsFinder.java b/plugins/git4idea/src/git4idea/roots/GitRootErrorsFinder.java index 8f68c17ef72f..8f03a93e0d0f 100644 --- a/plugins/git4idea/src/git4idea/roots/GitRootErrorsFinder.java +++ b/plugins/git4idea/src/git4idea/roots/GitRootErrorsFinder.java @@ -25,6 +25,7 @@ import git4idea.PlatformFacade; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -53,21 +54,17 @@ public class GitRootErrorsFinder { Collection gitRoots = new GitRootDetector(myProject, myPlatformFacade).detect().getRoots(); Collection errors = new ArrayList(); - Collection gitPaths = rootsToPaths(gitRoots); - errors.addAll(findExtraMappings(mappings, gitPaths)); - errors.addAll(findUnregisteredRoots(mappings, gitPaths)); + errors.addAll(findExtraMappings(mappings, rootsToPaths(gitRoots))); + errors.addAll(findUnregisteredRoots(gitRoots)); return errors; } - private Collection findUnregisteredRoots(List mappings, Collection gitPaths) { + private Collection findUnregisteredRoots(Collection gitRoots) { Collection errors = new ArrayList(); - if (hasProjectMapping(myPlatformFacade.getVcsManager(myProject).getDirectoryMappings())) { - return errors; - } - List mappedPaths = mappingsToPaths(mappings); - for (String gitPath : gitPaths) { - if (!mappedPaths.contains(gitPath)) { - errors.add(new VcsRootError(VcsRootError.Type.UNREGISTERED_ROOT, gitPath)); + Collection vcsRoots = Arrays.asList(myVcsManager.getRootsUnderVcs(myVcs)); + for (VirtualFile gitRoot : gitRoots) { + if (!vcsRoots.contains(gitRoot)) { + errors.add(new VcsRootError(VcsRootError.Type.UNREGISTERED_ROOT, gitRoot.getPath())); } } return errors; @@ -100,23 +97,4 @@ public class GitRootErrorsFinder { return gitPaths; } - private static List mappingsToPaths(List mappings) { - List paths = new ArrayList(); - for (VcsDirectoryMapping mapping : mappings) { - if (!mapping.isDefaultMapping()) { - paths.add(mapping.systemIndependentPath()); - } - } - return paths; - } - - private static boolean hasProjectMapping(List mappings) { - for (VcsDirectoryMapping mapping : mappings) { - if (mapping.isDefaultMapping()) { - return true; - } - } - return false; - } - } diff --git a/plugins/git4idea/tests/git4idea/roots/GitRootErrorsFinderTest.groovy b/plugins/git4idea/tests/git4idea/roots/GitRootErrorsFinderTest.groovy index cf002e7a74b6..f40b1a590cda 100644 --- a/plugins/git4idea/tests/git4idea/roots/GitRootErrorsFinderTest.groovy +++ b/plugins/git4idea/tests/git4idea/roots/GitRootErrorsFinderTest.groovy @@ -131,19 +131,20 @@ class GitRootErrorsFinderTest extends AbstractGitRootTest { } @Test - void "Project root, git below project folder not in a content root, then correct since folders are auto-detected"() { + void "Project root, git below project folder not in a content root, then unregistered root error"() { + // this is to be fixed: auto-detection of Git repositories in subfolders for the mapping doTest content_roots: ["."], git: ["community"], roots: [PROJECT], - errors: [] + errors: [unreg: ["community"]] } @Test - void "Project root, git for full project, content root, linked source, folder below project, then correct since folders are detected"() { + void "Project root, git for full project, content root, linked source, folder below project, then error in folder below"() { doTest content_roots: [".", "content_root", "../linked_source_root"], git: [".", "content_root", "../linked_source_root", "folder"], roots: [PROJECT], - errors: [] + errors: [unreg: ["folder"]] } @Test diff --git a/plugins/git4idea/tests/git4idea/test/GitMockVcsManager.groovy b/plugins/git4idea/tests/git4idea/test/GitMockVcsManager.groovy index 779ba4173494..4486690c47f2 100644 --- a/plugins/git4idea/tests/git4idea/test/GitMockVcsManager.groovy +++ b/plugins/git4idea/tests/git4idea/test/GitMockVcsManager.groovy @@ -57,7 +57,6 @@ public class GitMockVcsManager extends ProjectLevelVcsManager { List roots = myRoots.collect { new GitMockVirtualFile(it) } roots.addAll(myPlatformFacade.getProjectRootManager(myProject).getContentRoots()) roots -// new GitRootConverter(myProject, myPlatformFacade).convertRoots(roots) } @Override