Repository: vackosar/gitflow-incremental-builder
Pull request #79 (2019-01-14 22:10:07)

Fix issue #77: Evaluate excludePathRegex for untracked/uncommitted


Patch:
diff --git a/src/main/java/com/vackosar/gitflowincrementalbuild/control/DifferentFiles.java b/src/main/java/com/vackosar/gitflowincrementalbuild/control/DifferentFiles.java
index a7feaaf..2dea61f 100644
--- a/src/main/java/com/vackosar/gitflowincrementalbuild/control/DifferentFiles.java
+++ b/src/main/java/com/vackosar/gitflowincrementalbuild/control/DifferentFiles.java
@@ -26,6 +26,7 @@ import java.io.IOException;
 import java.nio.file.Path;
 import java.util.HashSet;
 import java.util.Set;
+import java.util.function.Predicate;
 import java.util.stream.Collectors;
 
 @Singleton
@@ -165,7 +166,7 @@ public class DifferentFiles {
             final Set<Path> paths = new HashSet<>();
             while (treeWalk.next()) {
                 Path path = gitDir.resolve(treeWalk.getPathString()).normalize();
-                if (! configuration.excludePathRegex.test(path.toString())) {
+                if (pathNotExcluded(path)) {
                     paths.add(path);
                 }
             }
@@ -194,7 +195,11 @@ public class DifferentFiles {
             if (configuration.untracked) {
                 changes.addAll(status.getUntracked());
             }
-            return changes.stream().map(workTree::resolve).map(Path::normalize).collect(Collectors.toSet());
+            return changes.stream()
+                    .map(workTree::resolve)
+                    .map(Path::normalize)
+                    .filter(this::pathNotExcluded)
+                    .collect(Collectors.toSet());
         }
 
         private RevCommit resolveReference(RevCommit base) throws IOException {
@@ -205,5 +210,9 @@ public class DifferentFiles {
                 return refHead;
             }
         }
+
+        private boolean pathNotExcluded(Path path) {
+            return !configuration.excludePathRegex.test(path.toString());
+        }
     }
 }


Test patch:
diff --git a/src/test/java/com/vackosar/gitflowincrementalbuild/control/DifferentFilesTest.java b/src/test/java/com/vackosar/gitflowincrementalbuild/control/DifferentFilesTest.java
index b0c0455..c026e49 100644
--- a/src/test/java/com/vackosar/gitflowincrementalbuild/control/DifferentFilesTest.java
+++ b/src/test/java/com/vackosar/gitflowincrementalbuild/control/DifferentFilesTest.java
@@ -9,6 +9,7 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
+import java.util.regex.Pattern;
 
 import org.apache.maven.execution.MavenSession;
 import org.codehaus.plexus.logging.Logger;
@@ -61,6 +62,15 @@ public class DifferentFilesTest extends BaseRepoTest {
         Assert.assertFalse(invokeUnderTest().contains(modifiedFilePath));
     }
 
+    @Test
+    public void listIncludingUncommitted_excluded() throws Exception {
+        Path modifiedFilePath = modifyTrackedFile(repoPath);
+        projectProperties.setProperty(Property.uncommited.fullName(), "true");
+        projectProperties.setProperty(Property.excludePathRegex.fullName(), Pattern.quote(modifiedFilePath.toString()));
+
+        Assert.assertFalse(invokeUnderTest().contains(modifiedFilePath));
+    }
+
     @Test
     public void listIncludingUntracked() throws Exception {
         Path newFilePath = createNewUntrackedFile(repoPath);
@@ -77,6 +87,15 @@ public class DifferentFilesTest extends BaseRepoTest {
         Assert.assertFalse(invokeUnderTest().contains(newFilePath));
     }
 
+    @Test
+    public void listIncludingUntracked_excluded() throws Exception {
+        Path newFilePath = createNewUntrackedFile(repoPath);
+        projectProperties.setProperty(Property.untracked.fullName(), "true");
+        projectProperties.setProperty(Property.excludePathRegex.fullName(), Pattern.quote(newFilePath.toString()));
+
+        Assert.assertFalse(invokeUnderTest().contains(newFilePath));
+    }
+
     @Test
     public void listWithCheckout() throws Exception {
         localRepoMock.getGit().reset().setRef(HEAD).setMode(ResetCommand.ResetType.HARD).call();