Search in sources :

Example 1 with GitAttribute

use of git4idea.attributes.GitAttribute in project intellij-community by JetBrains.

the class GitCrlfProblemsDetector method findFilesWithoutAttrs.

@NotNull
private Collection<VirtualFile> findFilesWithoutAttrs(@NotNull VirtualFile root, @NotNull Collection<VirtualFile> files) {
    GitRepository repository = myRepositoryManager.getRepositoryForRoot(root);
    if (repository == null) {
        LOG.warn("Repository is null for " + root);
        return Collections.emptyList();
    }
    Collection<String> interestingAttributes = Arrays.asList(GitAttribute.TEXT.getName(), GitAttribute.CRLF.getName());
    GitCommandResult result = myGit.checkAttr(repository, interestingAttributes, files);
    if (!result.success()) {
        LOG.warn(String.format("Couldn't git check-attr. Attributes: %s, files: %s", interestingAttributes, files));
        return Collections.emptyList();
    }
    GitCheckAttrParser parser = GitCheckAttrParser.parse(result.getOutput());
    Map<String, Collection<GitAttribute>> attributes = parser.getAttributes();
    Collection<VirtualFile> filesWithoutAttrs = new ArrayList<>();
    for (VirtualFile file : files) {
        ProgressIndicatorProvider.checkCanceled();
        String relativePath = FileUtil.getRelativePath(root.getPath(), file.getPath(), '/');
        Collection<GitAttribute> attrs = attributes.get(relativePath);
        if (attrs == null || !attrs.contains(GitAttribute.TEXT) && !attrs.contains(GitAttribute.CRLF)) {
            filesWithoutAttrs.add(file);
        }
    }
    return filesWithoutAttrs;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitRepository(git4idea.repo.GitRepository) GitCheckAttrParser(git4idea.attributes.GitCheckAttrParser) GitAttribute(git4idea.attributes.GitAttribute) GitCommandResult(git4idea.commands.GitCommandResult) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 GitAttribute (git4idea.attributes.GitAttribute)1 GitCheckAttrParser (git4idea.attributes.GitCheckAttrParser)1 GitCommandResult (git4idea.commands.GitCommandResult)1 GitRepository (git4idea.repo.GitRepository)1 NotNull (org.jetbrains.annotations.NotNull)1