From c544320aaada8ce6f70ebbabfb209c2331cce17b Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Wed, 17 Oct 2018 17:40:48 -0700 Subject: [PATCH] vcs: skip the "vendor" dir from root detection (IDEA-199926) It often contains template libraries downloaded e.g. by Composer framework. --- platform/util/resources/misc/registry.properties | 2 ++ .../intellij/openapi/vcs/roots/VcsRootDetectorImpl.java | 3 +++ .../com/intellij/openapi/vcs/roots/VcsRootDetectorTest.kt | 7 +++++++ 3 files changed, 12 insertions(+) diff --git a/platform/util/resources/misc/registry.properties b/platform/util/resources/misc/registry.properties index 113677f0e38f..09b2b7f3ecc0 100644 --- a/platform/util/resources/misc/registry.properties +++ b/platform/util/resources/misc/registry.properties @@ -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 diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootDetectorImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootDetectorImpl.java index 85d9f5f7cd37..fc4b1a6ec7fe 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootDetectorImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootDetectorImpl.java @@ -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 scanForRootsInsideDir(@NotNull VirtualFile root) { Set 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); diff --git a/platform/vcs-tests/testSrc/com/intellij/openapi/vcs/roots/VcsRootDetectorTest.kt b/platform/vcs-tests/testSrc/com/intellij/openapi/vcs/roots/VcsRootDetectorTest.kt index d4bed139f953..ac92550745aa 100644 --- a/platform/vcs-tests/testSrc/com/intellij/openapi/vcs/roots/VcsRootDetectorTest.kt +++ b/platform/vcs-tests/testSrc/com/intellij/openapi/vcs/roots/VcsRootDetectorTest.kt @@ -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): List {