git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrey Loskutov <loskutov@gmx.de>
To: git@vger.kernel.org
Subject: Single brackets matching in .gitignore rules
Date: Sun, 27 Sep 2015 00:01:10 +0200	[thread overview]
Message-ID: <2606743.RipZrg6Xoz@pinguin> (raw)

Hi,

I'm trying to make JGit .gitignore parser compatible to Git behavior and need help to understand some corner cases.

Git seem to fail to match file names if the ignore rule contain a single bracket '[' and seem to have inconsistent behavior for a single ']'.
For all experiments below I was using git 2.1.0 from Fedora 21 repositories.

Example table for '[':
----------------------
rule  | file | match?
----------------------
[           [          false
[*         [          false
*[         [          false
*[         a[        false
----------------------

I would expect that in all cases above Git ignore rules must match, since there is no valid character group defined and so the pattern should be interpreted literally.
However, it looks like Git simply gives up on parsing the rule, probably because it contains unmatched '[' character starting a (broken) character group.

Next, the surprising table for ']':
----------------------
rule  | file | match?
----------------------
]           ]          true
]*         ]          true
*]         ]          true
*]         a]        true
----------------------

Here Git does not give up on parsing, treats unmatched ']' character literally, and doesn't dislike that it is an "unmatched" end of a broken character group.
Why?

If Git interprets [ character only as part of the glob rules (character groups), it should interpret unmatched ] character equally.
Also if Git interprets unmatched  ] character literally, why not same behavior for the [ character?
IMHO the first table for single '[' character is just a bug in Git, and it should be consistent to the ']' table.

Anyway, it would be nice to hear what should be the "right" way to interpret the tables above.

BTW the only official documentation I found about ignore rules:

https://www.kernel.org/pub/software/scm/git/docs/gitignore.html
http://man7.org/linux/man-pages/man3/fnmatch.3.html
http://man7.org/linux/man-pages/man7/glob.7.html

-- 
Kind regards,
google.com/+AndreyLoskutov

             reply	other threads:[~2015-09-26 22:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-26 22:01 Andrey Loskutov [this message]
2015-09-27  8:58 ` Single brackets matching in .gitignore rules Andreas Schwab
2015-09-27 16:35   ` Andrey Loskutov
2015-09-28 13:15 ` Duy Nguyen
2015-09-28 17:40   ` Junio C Hamano
2015-09-28 17:46     ` Andrey Loskutov
2015-09-28 18:04       ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2606743.RipZrg6Xoz@pinguin \
    --to=loskutov@gmx.de \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).