From 9e841dd4ac8435b97333c380eaa34e7bf01be97e Mon Sep 17 00:00:00 2001 From: Xing Huang Date: Fri, 15 Mar 2024 15:19:15 -0500 Subject: PathFilterGroup: implement getPathsBestEffort() getPathsBestEffort() is a method in the TreeFilter class to retrieve file paths specified by the caller. PathFilterGroup do not propagate the paths of their subfilters as it does not implement the getPathsBestEffort() method, resulting in the caller only getting an empty list of paths. Override getPathsBestEffort() in PathFilterGroup to propagate subfilter values. Signed-off-by: Xing Huang Change-Id: I76bf08795360abc0874a7c258636d4f37da35060 --- .../jgit/treewalk/filter/PathFilterGroupTest.java | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'org.eclipse.jgit.test') diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java index 32bd40312f..1bb4939c85 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java @@ -11,6 +11,7 @@ package org.eclipse.jgit.treewalk.filter; import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -21,7 +22,9 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCacheEditor; @@ -30,6 +33,7 @@ import org.eclipse.jgit.dircache.DirCacheIterator; import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.errors.MissingObjectException; import org.eclipse.jgit.errors.StopWalkException; +import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.ObjectReader; import org.eclipse.jgit.lib.Sets; @@ -142,6 +146,29 @@ public class PathFilterGroupTest { assertFalse(longPathFilter.include(fakeWalk("a-nothing-in-common"))); } + @Test + public void testGetPathsBestEffort() { + String[] paths = { "path1", "path2", "path3" }; + Set expected = Arrays.stream(paths).map(Constants::encode) + .collect(Collectors.toSet()); + TreeFilter pathFilterGroup = PathFilterGroup.createFromStrings(paths); + Optional> bestEffortPaths = pathFilterGroup + .getPathsBestEffort(); + assertTrue(bestEffortPaths.isPresent()); + Set actual = bestEffortPaths.get(); + assertEquals(expected.size(), actual.size()); + for (byte[] actualPath : actual) { + boolean findMatch = false; + for (byte[] expectedPath : expected) { + if (Arrays.equals(actualPath, expectedPath)) { + findMatch = true; + break; + } + } + assertTrue(findMatch); + } + } + @Test public void testStopWalk() throws MissingObjectException, IncorrectObjectTypeException, IOException { -- cgit v1.2.3