mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Revert "Detect nested roots in folders for <Project> mapping."
Reason: detect nested folders can't be implemented easily - need change in ModuleDefaultVcsRootPolicy, not now.
This reverts commit d3f23906a8.
This commit is contained in:
@@ -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<VirtualFile> convertRoots(@NotNull List<VirtualFile> 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<VirtualFile> roots = new ArrayList<VirtualFile>();
|
||||
if (hasProjectMapping()) {
|
||||
roots.addAll(detectInfo.getRoots());
|
||||
}
|
||||
|
||||
HashSet<VirtualFile> listed = new HashSet<VirtualFile>();
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -135,7 +135,6 @@ public class GitVcs extends AbstractVcs<CommittedChangeList> {
|
||||
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<CommittedChangeList> {
|
||||
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<CommittedChangeList> {
|
||||
|
||||
@Override
|
||||
public RootsConvertor getCustomConvertor() {
|
||||
return myRootConverter;
|
||||
return GitRootConverter.INSTANCE;
|
||||
}
|
||||
|
||||
public static VcsKey getKey() {
|
||||
|
||||
@@ -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<VirtualFile> gitRoots = new GitRootDetector(myProject, myPlatformFacade).detect().getRoots();
|
||||
|
||||
Collection<VcsRootError> errors = new ArrayList<VcsRootError>();
|
||||
Collection<String> 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<VcsRootError> findUnregisteredRoots(List<VcsDirectoryMapping> mappings, Collection<String> gitPaths) {
|
||||
private Collection<VcsRootError> findUnregisteredRoots(Collection<VirtualFile> gitRoots) {
|
||||
Collection<VcsRootError> errors = new ArrayList<VcsRootError>();
|
||||
if (hasProjectMapping(myPlatformFacade.getVcsManager(myProject).getDirectoryMappings())) {
|
||||
return errors;
|
||||
}
|
||||
List<String> mappedPaths = mappingsToPaths(mappings);
|
||||
for (String gitPath : gitPaths) {
|
||||
if (!mappedPaths.contains(gitPath)) {
|
||||
errors.add(new VcsRootError(VcsRootError.Type.UNREGISTERED_ROOT, gitPath));
|
||||
Collection<VirtualFile> 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<String> mappingsToPaths(List<VcsDirectoryMapping> mappings) {
|
||||
List<String> paths = new ArrayList<String>();
|
||||
for (VcsDirectoryMapping mapping : mappings) {
|
||||
if (!mapping.isDefaultMapping()) {
|
||||
paths.add(mapping.systemIndependentPath());
|
||||
}
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
|
||||
private static boolean hasProjectMapping(List<VcsDirectoryMapping> mappings) {
|
||||
for (VcsDirectoryMapping mapping : mappings) {
|
||||
if (mapping.isDefaultMapping()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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 <Project> 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
|
||||
|
||||
@@ -57,7 +57,6 @@ public class GitMockVcsManager extends ProjectLevelVcsManager {
|
||||
List<VirtualFile> roots = myRoots.collect { new GitMockVirtualFile(it) }
|
||||
roots.addAll(myPlatformFacade.getProjectRootManager(myProject).getContentRoots())
|
||||
roots
|
||||
// new GitRootConverter(myProject, myPlatformFacade).convertRoots(roots)
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user