Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] PathMatcher behaviour is inconsistent with "git check-attr"

On Wed, Jun 28, 2017 at 9:11 PM, Dmitry Pavlenko <pavlenko@xxxxxxxxxxxxx> wrote:
Hello,
There's a case when PathMatcher behaviour differs from "git check-attr". If I create .gitattributes
file with the following content:

images/** attr=value

and then run

  $ git check-attr attr images
  images/: attr: unspecified

  $ git check-attr attr images/
  images/: attr: unspecified

  $ git check-attr attr images/x
  images/x: attr: value

If I do the same with PathMatcher.createPathMatcher(), with every reasonable parameters it says that
all the paths above match to the pattern "images/**". So it's an inconsistency with Git behaviour.

It's not a surprise because near line 234 of PathMatcher.java there's a comment

                                       if (matcher == matchers.size() - 2
                                                       && matchers.get(matcher + 1) == WILD)
                                               // ** can match *nothing*: a/b/** match also a/b
                                               return true;

stating that a/b/** should match a/b, what's wrong.

I've attached a patch fixing the problem for all my cases, but I was surprised why the code has
  matchers.size() - 2
and
  matcher + 1

instead of
  matchers.size() - 1
and
  matcher

I've changed it for the latter and the code still works. For me it makes more sense as it checks
whether current segment is double star and it is actually the last one.

Could you please have a look at those 4 lines and maybe apply my changes?

Thanks for your bug report and patch contribution.

Please sign the Eclipse contribution license agreement (CLA) [1] and follow the contributor guide [2]
to push your patch to Gerrit which we use for code review.


-Matthias 

Back to the top