package ee.shy.core;

import java.io.IOException;
import java.nio.file.*;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public final class IgnoreChecker {

    private final List<PathMatcher> pathMatchers = new ArrayList<>();

    private final Path rootPath;

    public IgnoreChecker(Path rootPath) throws IOException {
        this.rootPath = rootPath;
        Path shyIgnorePath = rootPath.resolve(".shyignore");
        if (Files.exists(shyIgnorePath)) {
            pathMatchers.addAll(Files.readAllLines(shyIgnorePath).stream().map(
                    string -> FileSystems.getDefault().getPathMatcher("glob:" + string)).collect(Collectors.toList())
            );
        }
    }

    public boolean isIgnored(Path path) throws IOException {
        if (Files.isHidden(path)) return true;
        for (PathMatcher pathMatcher : pathMatchers) {
            if (pathMatcher.matches(rootPath.relativize(path.normalize().toAbsolutePath()))) {
                return true;
            }
        }
        return false;
    }
}

@@ -84,25 +84,27 @@
 va.util.
-ArrayList
+Collections
 ;%0Aimport
@@ -245,28 +245,8 @@
 hers
- = new ArrayList%3C%3E()
 ;%0A%0A 
@@ -505,30 +505,18 @@
 hers
-.addAll(Files.readAllL
+ = Files.l
 ines
@@ -535,17 +535,8 @@
 th).
-stream().
 map(
@@ -652,17 +652,16 @@
 toList()
-)
 %0A       
@@ -666,16 +666,84 @@
        )
+;%0A        %7D else %7B%0A            pathMatchers = Collections.EMPTY_LIST
 ;%0A      
@@ -742,24 +742,25 @@
 ;%0A        %7D%0A
+%0A
     %7D%0A%0A    p
@@ -854,32 +854,117 @@
 )) return true;%0A
+        Path matchablePath = rootPath.relativize(path.normalize().toAbsolutePath());%0A
         for (Pat
@@ -1042,62 +1042,21 @@
 hes(
-rootPath.relativize(path.normalize().toAbsolut
+matchabl
 ePath
-())
 )) %7B

Fix minor code issues