vcs: try parent if content root is a file, add logging

This commit is contained in:
Kirill Likhodedov
2017-01-24 18:22:18 +03:00
parent f6454d2bce
commit 0209fc68d2
@@ -116,18 +116,27 @@ public class ModuleDefaultVcsRootPolicy extends DefaultVcsRootPolicy {
public VirtualFile getVcsRootFor(@NotNull VirtualFile file) {
FileIndexFacade indexFacade = PeriodicalTasksCloser.getInstance().safeGetService(myProject, FileIndexFacade.class);
if (myBaseDir != null && indexFacade.isValidAncestor(myBaseDir, file)) {
LOG.debug("File " + file + " is under project base dir " + myBaseDir);
return myBaseDir;
}
VirtualFile contentRoot = ProjectRootManager.getInstance(myProject).getFileIndex().getContentRootForFile(file, Registry.is("ide.hide.excluded.files"));
if (contentRoot != null && contentRoot.isDirectory()) {
return contentRoot;
if (contentRoot != null) {
LOG.debug("Content root for file " + file + " is " + contentRoot);
if (contentRoot.isDirectory()) {
return contentRoot;
}
VirtualFile parent = contentRoot.getParent();
LOG.debug("Content root is not a directory, using its parent " + parent);
return parent;
}
if (ProjectKt.isDirectoryBased(myProject)) {
VirtualFile ideaDir = ProjectKt.getStateStore(myProject).getDirectoryStoreFile();
if (ideaDir != null && VfsUtilCore.isAncestor(ideaDir, file, false)) {
LOG.debug("File " + file + " is under .idea");
return ideaDir;
}
}
LOG.debug("Couldn't find proper root for " + file);
return null;
}