From 2e4b5b544ffaacb66cc5d7e08da200eda5279813 Mon Sep 17 00:00:00 2001 From: Jente Sondervorst Date: Fri, 25 Oct 2024 15:10:17 +0200 Subject: [PATCH] showcase #105 --- .gitignore | 1 + .../jgit/ignore/ShowcaseBehaviour1Test.java | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/ShowcaseBehaviour1Test.java diff --git a/.gitignore b/.gitignore index 1671449eb18..9f29f344d74 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/.idea /.project /org.eclipse.jgit.benchmarks/dependency-reduced-pom.xml target/ diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/ShowcaseBehaviour1Test.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/ShowcaseBehaviour1Test.java new file mode 100644 index 00000000000..38525dd3bf7 --- /dev/null +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/ShowcaseBehaviour1Test.java @@ -0,0 +1,43 @@ +package org.eclipse.jgit.ignore; + +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.IOException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class ShowcaseBehaviour1Test { + + //Let's load a "file" containing a single rule for /directory/nested/. + //This should exclude the directory /directory/nested/again + @Test + public void IgnoreNodeUsesPathMatchTrue() throws IOException { + IgnoreNode ignoreNode = new IgnoreNode(); + ignoreNode.parse(new ByteArrayInputStream("/directory/nested/".getBytes())); + + IgnoreNode.MatchResult isIgnored = ignoreNode.isIgnored("/directory/nested/again", true); + + assertEquals(IgnoreNode.MatchResult.IGNORED, isIgnored); + // The result should not be CHECK_PARENT? + } + + //IgnoreNode.MatchResult isIgnored = ignoreNode.isIgnored("/directory/nested/again", true); + // ^^^^^^^^^ + // Path match is always sent as true (see difference in next test) + // The result is NOT correct + + @Test + public void fastIgnoreRuleForNestedDirectory() { + //This PASSES as isMatch returns true + FastIgnoreRule ignoreRule1 = new FastIgnoreRule("/directory/nested/"); + assertTrue(ignoreRule1.isMatch("/directory/nested/again", true, false)); // It matches the directory + // ^^^^^ + + //This FAILS as isMatch returns false + FastIgnoreRule ignoreRule2 = new FastIgnoreRule("/directory/nested/"); + assertTrue(ignoreRule2.isMatch("/directory/nested/again", true, true)); // It matches the directory + // ^^^^^ + } +}