diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsRootChecker.java b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsRootChecker.java index 5a194e65bb1c..b268b6dafaec 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsRootChecker.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsRootChecker.java @@ -15,7 +15,6 @@ */ package com.intellij.openapi.vcs; -import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; import java.util.Collection; @@ -29,14 +28,15 @@ import java.util.Collection; public interface VcsRootChecker { /** - * @return VCS roots which are not registered in the Settings | Version Control. + * @return Paths to VCS roots which are not registered in the Settings | Version Control. */ @NotNull - Collection getUnregisteredRoots(); + Collection getUnregisteredRoots(); /** + * * @param directory root to be checked. * @return true if the given directory is not a VCS root. */ - boolean isInvalidRoot(@NotNull String directory); + boolean isInvalidMapping(@NotNull VcsDirectoryMapping mapping); } diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsRootError.java b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsRootError.java index c82bf55bbee0..5fde942a9b12 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsRootError.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsRootError.java @@ -15,7 +15,6 @@ */ package com.intellij.openapi.vcs; -import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; /** @@ -29,16 +28,16 @@ import org.jetbrains.annotations.NotNull; public class VcsRootError { private final @NotNull Type myType; - private final @NotNull VirtualFile myRoot; + private final @NotNull String myMapping; public enum Type { - EXTRA_ROOT, + EXTRA_MAPPING, UNREGISTERED_ROOT } - public VcsRootError(@NotNull Type type, @NotNull VirtualFile root) { + public VcsRootError(@NotNull Type type, @NotNull String mapping) { myType = type; - myRoot = root; + myMapping = mapping; } @NotNull @@ -47,13 +46,13 @@ public class VcsRootError { } @NotNull - public VirtualFile getRoot() { - return myRoot; + public String getMapping() { + return myMapping; } @Override public String toString() { - return String.format("GitRootError{myType=%s, myRoot=%s}", myType, myRoot); + return String.format("VcsRootError{%s - %s}", myType, myMapping); } @Override @@ -63,7 +62,7 @@ public class VcsRootError { VcsRootError error = (VcsRootError)o; - if (!myRoot.equals(error.myRoot)) return false; + if (!myMapping.equals(error.myMapping)) return false; if (myType != error.myType) return false; return true; @@ -73,7 +72,7 @@ public class VcsRootError { @Override public int hashCode() { int result = myType != null ? myType.hashCode() : 0; - result = 31 * result + myRoot.hashCode(); + result = 31 * result + myMapping.hashCode(); return result; } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsDirectoryConfigurationPanel.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsDirectoryConfigurationPanel.java index f8173d08c7c5..cc1a57251e3b 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsDirectoryConfigurationPanel.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsDirectoryConfigurationPanel.java @@ -116,7 +116,7 @@ public class VcsDirectoryConfigurationPanel extends PanelWithButtons implements private boolean mappingIsError(VcsDirectoryMapping mapping) { String vcs = mapping.getVcs(); VcsRootChecker checker = myCheckers.get(vcs); - return checker != null && checker.isInvalidRoot(mapping.getDirectory()); + return checker != null && checker.isInvalidMapping(mapping); } } @@ -395,14 +395,14 @@ public class VcsDirectoryConfigurationPanel extends PanelWithButtons implements Box box = Box.createVerticalBox(); for (Map.Entry entry : myCheckers.entrySet()) { VcsRootChecker checker = entry.getValue(); - for (final VirtualFile root : checker.getUnregisteredRoots()) { + for (final String root : checker.getUnregisteredRoots()) { final String vcs = entry.getKey(); - String title = "Unregistered " + vcs + " root: " + FileUtil.toSystemDependentName(root.getPresentableUrl()); + String title = "Unregistered " + vcs + " root: " + FileUtil.toSystemDependentName(root); final VcsRootErrorLabel vcsRootErrorLabel = new VcsRootErrorLabel(title); vcsRootErrorLabel.setAddRootLinkHandler(new Runnable() { @Override public void run() { - addMapping(new VcsDirectoryMapping(root.getPath(), vcs)); + addMapping(new VcsDirectoryMapping(root, vcs)); vcsRootErrorLabel.setVisible(false); } }); diff --git a/plugins/git4idea/src/git4idea/roots/GitRootChecker.java b/plugins/git4idea/src/git4idea/roots/GitRootChecker.java index fa0ff1f2634f..ec5e97cf4efe 100644 --- a/plugins/git4idea/src/git4idea/roots/GitRootChecker.java +++ b/plugins/git4idea/src/git4idea/roots/GitRootChecker.java @@ -16,10 +16,9 @@ package git4idea.roots; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.vcs.VcsDirectoryMapping; import com.intellij.openapi.vcs.VcsRootChecker; import com.intellij.openapi.vcs.VcsRootError; -import com.intellij.openapi.vfs.VirtualFile; import git4idea.PlatformFacade; import org.jetbrains.annotations.NotNull; @@ -32,30 +31,44 @@ import java.util.Collection; */ public class GitRootChecker implements VcsRootChecker { - private final Collection myErrors; + @NotNull private final Collection myErrors; + private final boolean myProjectMappingIsInvalid; - public GitRootChecker(Project project, PlatformFacade platformFacade) { + public GitRootChecker(@NotNull Project project, @NotNull PlatformFacade platformFacade) { myErrors = new GitRootErrorsFinder(project, platformFacade).find(); + myProjectMappingIsInvalid = isProjectMappingInvalid(); + } + + private boolean isProjectMappingInvalid() { + for (VcsRootError error : myErrors) { + if (error.getType() == VcsRootError.Type.EXTRA_MAPPING && error.getMapping().equals(VcsDirectoryMapping.PROJECT_CONSTANT)) { + return true; + } + } + return false; } @NotNull @Override - public Collection getUnregisteredRoots() { - Collection roots = new ArrayList(); + public Collection getUnregisteredRoots() { + Collection roots = new ArrayList(); for (VcsRootError error : myErrors) { if (error.getType() == VcsRootError.Type.UNREGISTERED_ROOT) { - roots.add(error.getRoot()); + roots.add(error.getMapping()); } } return roots; } @Override - public boolean isInvalidRoot(@NotNull String directory) { + public boolean isInvalidMapping(@NotNull VcsDirectoryMapping mapping) { // this information is available in myErrors, // but the method may be called in VcsDirectoryConfigurationPanel after adding a mapping (to highlight errors right away) // in which case ProjectLevelVcsManager#getAllVcsRoots() is not aware of new roots yet, // while GitRootErrorsFinder relies on the set of roots returned from ProjectLevelVcsManager. - return !new File(FileUtil.toSystemDependentName(directory), ".git").exists(); + if (mapping.isDefaultMapping()) { + return myProjectMappingIsInvalid; + } + return !new File(mapping.getDirectory(), ".git").exists(); } } diff --git a/plugins/git4idea/src/git4idea/roots/GitRootDetectInfo.java b/plugins/git4idea/src/git4idea/roots/GitRootDetectInfo.java index c4273b3d64ac..6995de9bcfe6 100644 --- a/plugins/git4idea/src/git4idea/roots/GitRootDetectInfo.java +++ b/plugins/git4idea/src/git4idea/roots/GitRootDetectInfo.java @@ -57,7 +57,7 @@ public class GitRootDetectInfo { } @NotNull - Collection getRoots() { + public Collection getRoots() { return new ArrayList(myRoots); } diff --git a/plugins/git4idea/src/git4idea/roots/GitRootErrorsFinder.java b/plugins/git4idea/src/git4idea/roots/GitRootErrorsFinder.java index ba28d0ec1a25..8f03a93e0d0f 100644 --- a/plugins/git4idea/src/git4idea/roots/GitRootErrorsFinder.java +++ b/plugins/git4idea/src/git4idea/roots/GitRootErrorsFinder.java @@ -16,7 +16,9 @@ package git4idea.roots; import com.intellij.openapi.project.Project; +import com.intellij.openapi.vcs.AbstractVcs; import com.intellij.openapi.vcs.ProjectLevelVcsManager; +import com.intellij.openapi.vcs.VcsDirectoryMapping; import com.intellij.openapi.vcs.VcsRootError; import com.intellij.openapi.vfs.VirtualFile; import git4idea.PlatformFacade; @@ -25,6 +27,7 @@ import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.List; /** * Detects actual Git roots and compares them to the ones registered in Settings | Version Control. @@ -35,29 +38,63 @@ public class GitRootErrorsFinder { private final @NotNull Project myProject; private final @NotNull PlatformFacade myPlatformFacade; + private final @NotNull ProjectLevelVcsManager myVcsManager; + private final AbstractVcs myVcs; public GitRootErrorsFinder(@NotNull Project project, @NotNull PlatformFacade platformFacade) { myProject = project; myPlatformFacade = platformFacade; + myVcsManager = myPlatformFacade.getVcsManager(myProject); + myVcs = myPlatformFacade.getVcs(myProject); } @NotNull public Collection find() { - ProjectLevelVcsManager vcsManager = myPlatformFacade.getVcsManager(myProject); - Collection vcsRoots = Arrays.asList(vcsManager.getRootsUnderVcs(myPlatformFacade.getVcs(myProject))); + List mappings = myVcsManager.getDirectoryMappings(myVcs); Collection gitRoots = new GitRootDetector(myProject, myPlatformFacade).detect().getRoots(); + Collection errors = new ArrayList(); - for (VirtualFile vcsRoot : vcsRoots) { - if (!gitRoots.contains(vcsRoot)) { - errors.add(new VcsRootError(VcsRootError.Type.EXTRA_ROOT, vcsRoot)); - } - } + errors.addAll(findExtraMappings(mappings, rootsToPaths(gitRoots))); + errors.addAll(findUnregisteredRoots(gitRoots)); + return errors; + } + + private Collection findUnregisteredRoots(Collection gitRoots) { + Collection errors = new ArrayList(); + Collection vcsRoots = Arrays.asList(myVcsManager.getRootsUnderVcs(myVcs)); for (VirtualFile gitRoot : gitRoots) { if (!vcsRoots.contains(gitRoot)) { - errors.add(new VcsRootError(VcsRootError.Type.UNREGISTERED_ROOT, gitRoot)); + errors.add(new VcsRootError(VcsRootError.Type.UNREGISTERED_ROOT, gitRoot.getPath())); } } return errors; } + private static Collection findExtraMappings(List mappings, Collection gitPaths) { + Collection errors = new ArrayList(); + for (VcsDirectoryMapping mapping : mappings) { + if (mapping.isDefaultMapping()) { + if (gitPaths.isEmpty()) { + errors.add(new VcsRootError(VcsRootError.Type.EXTRA_MAPPING, VcsDirectoryMapping.PROJECT_CONSTANT)); + } + } + else { + String mappedPath = mapping.systemIndependentPath(); + if (!gitPaths.contains(mappedPath)) { + errors.add(new VcsRootError(VcsRootError.Type.EXTRA_MAPPING, mappedPath)); + } + } + } + return errors; + } + + @NotNull + private static Collection rootsToPaths(@NotNull Collection gitRoots) { + Collection gitPaths = new ArrayList(gitRoots.size()); + for (VirtualFile root : gitRoots) { + gitPaths.add(root.getPath()); + } + return gitPaths; + } + } diff --git a/plugins/git4idea/src/git4idea/roots/GitRootProblemNotifier.java b/plugins/git4idea/src/git4idea/roots/GitRootProblemNotifier.java index 14220d6bbe20..dc83f790eb27 100644 --- a/plugins/git4idea/src/git4idea/roots/GitRootProblemNotifier.java +++ b/plugins/git4idea/src/git4idea/roots/GitRootProblemNotifier.java @@ -24,8 +24,8 @@ import com.intellij.openapi.options.ShowSettingsUtil; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.vcs.VcsDirectoryMapping; import com.intellij.openapi.vcs.VcsRootError; -import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.Function; import git4idea.PlatformFacade; import org.jetbrains.annotations.NotNull; @@ -73,8 +73,8 @@ public class GitRootProblemNotifier { return; } - Collection unregisteredRoots = getUnregisteredRoots(errors); - Collection invalidRoots = getInvalidRoots(errors); + Collection unregisteredRoots = getUnregisteredRoots(errors); + Collection invalidRoots = getInvalidRoots(errors); String title = makeTitle(unregisteredRoots, invalidRoots); String description = makeDescription(unregisteredRoots, invalidRoots); @@ -106,35 +106,38 @@ public class GitRootProblemNotifier { } @SuppressWarnings("StringConcatenationInsideStringBufferAppend") - private static String makeDescription(@NotNull Collection unregisteredRoots, @NotNull Collection invalidRoots) { - Function rootToString = new Function() { + private static String makeDescription(@NotNull Collection unregisteredRoots, @NotNull Collection invalidRoots) { + Function rootToDisplayableString = new Function() { @Override - public String fun(VirtualFile virtualFile) { - return FileUtil.toSystemDependentName(virtualFile.getPath()); + public String fun(String path) { + if (path.equals(VcsDirectoryMapping.PROJECT_CONSTANT)) { + return StringUtil.escapeXml(path); + } + return FileUtil.toSystemDependentName(path); } }; StringBuilder description = new StringBuilder(); if (!invalidRoots.isEmpty()) { if (invalidRoots.size() == 1) { - description.append("The directory " + rootToString.fun(invalidRoots.iterator().next()) + " is registered as a Git root, " + - "but it is not."); + description.append("The directory " + rootToDisplayableString.fun(invalidRoots.iterator().next()) + " is registered as a Git root, " + + "but no Git repositories were found there."); } else { description.append("The following directories are registered as Git roots, but they are not:
" + - StringUtil.join(invalidRoots, rootToString, ", ")); + StringUtil.join(invalidRoots, rootToDisplayableString, ", ")); } description.append("
"); } if (!unregisteredRoots.isEmpty()) { if (unregisteredRoots.size() == 1) { - description.append("The directory " + rootToString.fun(unregisteredRoots.iterator().next()) + " is under Git, " + + description.append("The directory " + rootToDisplayableString.fun(unregisteredRoots.iterator().next()) + " is under Git, " + "but is not registered in the Settings."); } else { description.append("The following directories are roots of Git repositories, but they are not registered in the Settings:
" + - StringUtil.join(unregisteredRoots, rootToString, ", ")); + StringUtil.join(unregisteredRoots, rootToDisplayableString, ", ")); } description.append("
"); } @@ -145,10 +148,10 @@ public class GitRootProblemNotifier { } @NotNull - private static String makeTitle(@NotNull Collection unregisteredRoots, @NotNull Collection invalidRoots) { + private static String makeTitle(@NotNull Collection unregisteredRoots, @NotNull Collection invalidRoots) { String title; if (unregisteredRoots.isEmpty()) { - title = "Invalid Git " + pluralize("root", invalidRoots.size()); + title = "Invalid Git root " + pluralize("mapping", invalidRoots.size()); } else if (invalidRoots.isEmpty()) { title = "Unregistered Git " + pluralize("root", unregisteredRoots.size()) + " detected"; @@ -160,21 +163,21 @@ public class GitRootProblemNotifier { } @NotNull - private static Collection getUnregisteredRoots(@NotNull Collection errors) { + private static Collection getUnregisteredRoots(@NotNull Collection errors) { return filterErrorsByType(errors, VcsRootError.Type.UNREGISTERED_ROOT); } @NotNull - private static Collection getInvalidRoots(@NotNull Collection errors) { - return filterErrorsByType(errors, VcsRootError.Type.EXTRA_ROOT); + private static Collection getInvalidRoots(@NotNull Collection errors) { + return filterErrorsByType(errors, VcsRootError.Type.EXTRA_MAPPING); } @NotNull - private static Collection filterErrorsByType(@NotNull Collection errors, @NotNull VcsRootError.Type type) { - Collection roots = new ArrayList(); + private static Collection filterErrorsByType(@NotNull Collection errors, @NotNull VcsRootError.Type type) { + Collection roots = new ArrayList(); for (VcsRootError error : errors) { if (error.getType() == type) { - roots.add(error.getRoot()); + roots.add(error.getMapping()); } } return roots; diff --git a/plugins/git4idea/tests/git4idea/roots/AbstractGitRootTest.groovy b/plugins/git4idea/tests/git4idea/roots/AbstractGitRootTest.groovy index e75e0e350bc8..c05dac669040 100644 --- a/plugins/git4idea/tests/git4idea/roots/AbstractGitRootTest.groovy +++ b/plugins/git4idea/tests/git4idea/roots/AbstractGitRootTest.groovy @@ -37,15 +37,15 @@ class AbstractGitRootTest { * And creates an instance of the project. * @param gitRoots path to actual .git roots, relative to the project dir. */ - Project initProject(Collection gitRoots, Collection projectStructure, Collection linkedRoots) { + Project initProject(Collection gitRoots, Collection projectStructure, Collection contentRoots = []) { String projectDir = createDirs(gitRoots) Project project = [ getBaseDir: { new GitMockVirtualFile(projectDir) } ] as Project createProjectStructure(project, projectStructure); - createProjectStructure(project, linkedRoots); + createProjectStructure(project, contentRoots); - linkedRoots.each { myPlatformFacade.myProjectRootManager.myContentRoots << GitMockVirtualFile.fromPath(it, project)} + contentRoots.each { myPlatformFacade.myProjectRootManager.myContentRoots << GitMockVirtualFile.fromPath(it, project)} project } diff --git a/plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.groovy b/plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.groovy index fc8d15dd262a..9611768ef1e4 100644 --- a/plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.groovy +++ b/plugins/git4idea/tests/git4idea/roots/GitRootDetectorTest.groovy @@ -120,39 +120,39 @@ class GitRootDetectorTest extends AbstractGitRootTest { @Test void "linked source root alone should be detected"() { - doTest linked_roots: ["../linked_root"], - gits: ["../linked_root"], - expected: ["../linked_root"], - full: false, - below: false + doTest content_roots: ["../linked_root"], + gits: ["../linked_root"], + expected: ["../linked_root"], + full: false, + below: false } @Test void "linked source root and project root should be detected"() { - doTest linked_roots: ["../linked_root"], - gits: [".", "../linked_root"], - expected: [".", "../linked_root"], - full: true, - below: false + doTest content_roots: ["../linked_root"], + gits: [".", "../linked_root"], + expected: [".", "../linked_root"], + full: true, + below: false } @Test void "linked source below Git"() { - doTest linked_roots: ["../linked_root/src"], - gits: [".", "../linked_root"], - expected: [".", "../linked_root"], - full: true, - below: false + doTest content_roots: ["../linked_root/src"], + gits: [".", "../linked_root"], + expected: [".", "../linked_root"], + full: true, + below: false } @Test // This is a test of performance optimization via limitation: don't scan deep though the whole VFS void "don't scan deeper than 2 levels below a content root"() { - doTest linked_roots: ["content_root"], - gits: ["community", "content_root/lev1/lev2", "content_root2/lev1/lev2/lev3"], - expected: ["community", "content_root/lev1/lev2"], - full: false, - below: false + doTest content_roots: ["content_root"], + gits: ["community", "content_root/lev1/lev2", "content_root2/lev1/lev2/lev3"], + expected: ["community", "content_root/lev1/lev2"], + full: false, + below: false } /** @@ -161,7 +161,7 @@ class GitRootDetectorTest extends AbstractGitRootTest { * @param map */ private void doTest(Map map) { - myProject = initProject(map.gits, map.project, map.linked_roots) + myProject = initProject(map.gits, map.project, map.content_roots) testInfo empty: map.expected.empty, full : map.full, roots: map.expected, diff --git a/plugins/git4idea/tests/git4idea/roots/GitRootErrorsFinderTest.groovy b/plugins/git4idea/tests/git4idea/roots/GitRootErrorsFinderTest.groovy index e207097d05f1..f40b1a590cda 100644 --- a/plugins/git4idea/tests/git4idea/roots/GitRootErrorsFinderTest.groovy +++ b/plugins/git4idea/tests/git4idea/roots/GitRootErrorsFinderTest.groovy @@ -16,6 +16,8 @@ package git4idea.roots import com.intellij.openapi.project.Project +import com.intellij.openapi.vcs.VcsDirectoryMapping +import com.intellij.openapi.vcs.VcsRootError import git4idea.test.GitMockVcsManager import git4idea.test.GitTestPlatformFacade import org.junit.Before @@ -23,8 +25,6 @@ import org.junit.Test import static git4idea.test.GitGTestUtil.toAbsolute import static junit.framework.Assert.assertEquals -import git4idea.test.GitMockVirtualFile -import com.intellij.openapi.vcs.VcsRootError /** * @@ -32,6 +32,8 @@ import com.intellij.openapi.vcs.VcsRootError */ class GitRootErrorsFinderTest extends AbstractGitRootTest { + static final String PROJECT = VcsDirectoryMapping.PROJECT_CONSTANT + Project myProject GitTestPlatformFacade myPlatformFacade GitMockVcsManager myVcsManager @@ -103,9 +105,66 @@ class GitRootErrorsFinderTest extends AbstractGitRootTest { roots: [".", "contrib"], errors: [unreg: ["..", "community"], extra: [".", "contrib"]] } + + @Test + void "Project root, no gits, then error about extra root"() { + doTest content_roots: ["."], + git: [], + roots: [PROJECT], + errors: [extra: [PROJECT]] + } + + @Test + void "Project root, full under git, then correct"() { + doTest content_roots: ["."], + git: ["."], + roots: [PROJECT], + errors: [] + } + + @Test + void "Project root, git for a content root below project, then correct"() { + doTest content_roots: [".", "content_root"], + git: [""], + roots: [PROJECT], + errors: [] + } + + @Test + 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: [unreg: ["community"]] + } + + @Test + 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: [unreg: ["folder"]] + } + + @Test + void "Project root, root for folder, git for full project, content root, linked source, folder below project, then correct"() { + doTest content_roots: [".", "content_root", "../linked_source_root"], + git: [".", "content_root", "../linked_source_root", "folder"], + roots: [PROJECT, "folder"], + errors: [] + } + + @Test + void "Project root, git like in IDEA project, then correct"() { + doTest content_roots: [".", "community", "contrib"], + git: [".", "community", "contrib"], + roots: [PROJECT], + errors: [] + } private void doTest(Map map) { - myProject = initProject(map.git, [], []) + myProject = initProject(map.git, [], map.content_roots) myVcsManager = (GitMockVcsManager) myPlatformFacade.getVcsManager(myProject) addVcsRoots(map.roots) @@ -120,17 +179,22 @@ class GitRootErrorsFinderTest extends AbstractGitRootTest { void addVcsRoots(Collection relativeRoots) { relativeRoots.each { - String root = toAbsolute(it, myProject) - myVcsManager.addRoots(root) + if (it.equals(PROJECT)) { + myVcsManager.setProjectRootMapping() + } + else { + String root = toAbsolute(it, myProject) + myVcsManager.addRoots(root) + } } } VcsRootError unreg(String path) { - return new VcsRootError(VcsRootError.Type.UNREGISTERED_ROOT, new GitMockVirtualFile(toAbsolute(path, myProject))) + return new VcsRootError(VcsRootError.Type.UNREGISTERED_ROOT, toAbsolute(path, myProject)) } VcsRootError extra(String path) { - return new VcsRootError(VcsRootError.Type.EXTRA_ROOT, new GitMockVirtualFile(toAbsolute(path, myProject))) + return new VcsRootError(VcsRootError.Type.EXTRA_MAPPING, path.equals(PROJECT) ? PROJECT : toAbsolute(path, myProject)) } diff --git a/plugins/git4idea/tests/git4idea/test/GitMockVcsManager.groovy b/plugins/git4idea/tests/git4idea/test/GitMockVcsManager.groovy index fd056f5bea8b..4486690c47f2 100644 --- a/plugins/git4idea/tests/git4idea/test/GitMockVcsManager.groovy +++ b/plugins/git4idea/tests/git4idea/test/GitMockVcsManager.groovy @@ -16,6 +16,7 @@ package git4idea.test import com.intellij.openapi.editor.markup.TextAttributes +import com.intellij.openapi.project.Project import com.intellij.openapi.vcs.history.VcsHistoryCache import com.intellij.openapi.vcs.impl.ContentRevisionCache import com.intellij.openapi.vcs.impl.VcsDescriptor @@ -24,6 +25,7 @@ import com.intellij.openapi.vcs.update.UpdatedFiles import com.intellij.openapi.vfs.VirtualFile import com.intellij.util.PairProcessor import com.intellij.util.Processor +import git4idea.PlatformFacade import com.intellij.openapi.vcs.* /** @@ -32,20 +34,38 @@ import com.intellij.openapi.vcs.* */ public class GitMockVcsManager extends ProjectLevelVcsManager { + Project myProject + PlatformFacade myPlatformFacade Collection myRoots = [] + boolean myProjectRootMapping = false + + GitMockVcsManager(Project project, PlatformFacade facade) { + myProject = project + myPlatformFacade = facade + } void addRoots(String... roots) { roots.each { myRoots << it } } + void setProjectRootMapping() { + myProjectRootMapping = true + } + @Override VirtualFile[] getRootsUnderVcs(AbstractVcs vcs) { - myRoots.collect { new GitMockVirtualFile(it) } + List roots = myRoots.collect { new GitMockVirtualFile(it) } + roots.addAll(myPlatformFacade.getProjectRootManager(myProject).getContentRoots()) + roots } @Override List getDirectoryMappings() { - myRoots.collect { new VcsDirectoryMapping(it, "Git") } + List roots = myRoots.collect { new VcsDirectoryMapping(it, "Git") } + if (myProjectRootMapping) { + roots << new VcsDirectoryMapping("", "Git") + } + roots } @Override diff --git a/plugins/git4idea/tests/git4idea/test/GitTestPlatformFacade.groovy b/plugins/git4idea/tests/git4idea/test/GitTestPlatformFacade.groovy index 9b0171b086d7..6dedef7e49aa 100644 --- a/plugins/git4idea/tests/git4idea/test/GitTestPlatformFacade.groovy +++ b/plugins/git4idea/tests/git4idea/test/GitTestPlatformFacade.groovy @@ -38,7 +38,6 @@ public class GitTestPlatformFacade implements PlatformFacade { GitMockProjectRootManager myProjectRootManager public GitTestPlatformFacade() { - myVcsManager = new GitMockVcsManager() myTestDialogManager = new TestDialogManager() myProjectRootManager = new GitMockProjectRootManager() } @@ -46,6 +45,9 @@ public class GitTestPlatformFacade implements PlatformFacade { @NotNull @Override ProjectLevelVcsManager getVcsManager(@NotNull Project project) { + if (!myVcsManager) { + myVcsManager = new GitMockVcsManager(project, this) + } return myVcsManager }