vcs: skip the "vendor" dir from root detection (IDEA-199926)

It often contains template libraries downloaded e.g. by Composer framework.
This commit is contained in:
Kirill Likhodedov
2018-10-17 17:40:48 -07:00
parent ec407fdbcd
commit c544320aaa
3 changed files with 12 additions and 0 deletions
@@ -527,6 +527,8 @@ vcs.history.refine.description=Use a refining algorithm on file history that eli
vcs.executable.validator.timeout.sec=60
vcs.root.detector.folder.depth=-1
vcs.root.detector.folder.depth.description=How deep should the IDE scan the file tree, searching for Git/Hg roots in the project. Set to -1 to scan the whole file tree.
vcs.root.detector.skip.vendor=true
vcs.root.detector.skip.vendor.description=If true, Git/Hg roots won't be detected under directories called 'vendor'.
vcs.root.auto.add=true
vcs.root.auto.add.description=Automatically register detected Git/Hg roots.
vcs.root.auto.add.nofity=false
@@ -5,6 +5,7 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.vcs.AbstractVcs;
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
import com.intellij.openapi.vcs.VcsRoot;
@@ -18,6 +19,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.*;
import static com.intellij.openapi.vfs.VirtualFileVisitor.CONTINUE;
import static com.intellij.openapi.vfs.VirtualFileVisitor.SKIP_CHILDREN;
public class VcsRootDetectorImpl implements VcsRootDetector {
private static final Logger LOG = Logger.getInstance(VcsRootDetectorImpl.class);
@@ -103,6 +105,7 @@ public class VcsRootDetectorImpl implements VcsRootDetector {
private Set<VcsRoot> scanForRootsInsideDir(@NotNull VirtualFile root) {
Set<VcsRoot> roots = new HashSet<>();
VcsRootScanner.visitDirsRecursivelyWithoutExcluded(myProject, myProjectManager, root, dir -> {
if (Registry.is("vcs.root.detector.skip.vendor") && dir.getName().equalsIgnoreCase("vendor")) return SKIP_CHILDREN;
AbstractVcs vcs = getVcsFor(dir);
if (vcs != null) {
LOG.debug("Found VCS " + vcs + " in " + dir);
@@ -125,6 +125,13 @@ class VcsRootDetectorTest : VcsRootBaseTest() {
expect(roots[0])
}
fun `test dont scan inside vendor folder`() {
projectRoot.initRepository()
createVcsRoots("vendor", "vendor/child/child")
expect(projectRoot)
}
private fun createVcsRoots(vararg relativePaths: String) = createVcsRoots(listOf(*relativePaths))
private fun createVcsRoots(relativePaths: Collection<String>): List<VirtualFile> {