Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jgit-dev] IgnoreNode.isIgnored() (Was: [Announce] JGit / EGit Release 4.11.0.201803080745-r)

> On Mar 10, 2018, at 18:18, Matthias Sohn <matthias.sohn@xxxxxxxxx> wrote:
> 
> On Sat, Mar 10, 2018 at 4:04 PM, Rüdiger Herrmann <ruediger.herrmann@xxxxxx> wrote:
> Dear JGit devs,
> 
> the following test used to work with JGit 4.10 and earlier. After updating to version 4.11, the test fails:
> 
>   @Test
>   public void testIsIgnored() throws IOException {
>     IgnoreNode ignoreNode = new IgnoreNode();
>     ignoreNode.parse( new ByteArrayInputStream( "bin/".getBytes( StandardCharsets.UTF_8 ) ) );
> 
>     MatchResult matchResult = ignoreNode.isIgnored( "bin/Foo.class", false );
> 
>     assertEquals( MatchResult.IGNORED, matchResult );
>   }
> 
> Is this a regression or am I doing something wrong?
> 
> bisecting between 4.10 and 4.11 yields the following commit causing this test to fail:
> 
> https://git.eclipse.org/r/#/c/117186/
> 
> commit 78420b7d0a65d591d00f32675efb0a42cda6c84a
> Author: Marc Strapetz <marc.strapetz@xxxxxxxxxxx>
> Date:   Fri Feb 23 13:34:23 2018 +0100
> 
>     Fix processing of gitignore negations
> 
>     Processing of negated rules, like !bin/ was not working correctly: they
>     were interpreted too broad, resulting in unexpected untracked files
>     which should actually be ignored
> 
>     Bug: 409664
>     Change-Id: I0a422fd6607941461bf2175c9105a0311612efa0
>     Signed-off-by: Marc Strapetz <marc.strapetz@xxxxxxxxxxx> 
> 

IMO the test is flawed. The git ignore pattern “bin/“ definitely doesn’t match the file “bin/Foo.class”.

Exclusion processing in git (and in JGit) is a recursive directory traversal: git and JGit will thus first
visit the directory “bin”, which _will_ match, and then will prune that whole subtree.

Correct exclusion information is thus available only during a TreeWalk (same for gitattributes). Simply
creating an IgnoreNode and then throwing an arbitrary path at it may give different results, as in this
case. Note that with a file pattern like “bin/*” or “bin/**” the test might work. But certainly not with a
directory pattern.

Maybe that whole IgnoreNode.isIgnored() method should be removed — it isn’t called in JGit or EGit.





Back to the top