{"thread":{"id":"40435","subject":"Single brackets matching in .gitignore rules","startedAt":"2015-09-26T22:01:10Z","lastAt":"2015-09-28T18:04:46Z","messageCount":7,"participants":["Andrey Loskutov","Andreas Schwab","Duy Nguyen","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"270787","messageId":"2606743.RipZrg6Xoz@pinguin","threadId":"40435","inReplyTo":null,"subject":"Single brackets matching in .gitignore rules","fromName":"Andrey Loskutov","fromEmail":"loskutov@gmx.de","sentAt":"2015-09-26T22:01:10Z","receivedAt":"2015-09-26T22:01:10Z","isPatch":false,"sender":{"key":"loskutov@gmx.de","avatar":"https://gravatar.com/avatar/3e41c7c1fe4dc85cfdccfa6ab6d1be5b6ba0c0611245e1fc7aedc6e9d77b76ab?d=mp&s=160"},"body":"Hi,\n\nI'm trying to make JGit .gitignore parser compatible to Git behavior and need help to understand some corner cases.\n\nGit seem to fail to match file names if the ignore rule contain a single bracket '[' and seem to have inconsistent behavior for a single ']'.\nFor all experiments below I was using git 2.1.0 from Fedora 21 repositories.\n\nExample table for '[':\n----------------------\nrule  | file | match?\n----------------------\n[           [          false\n[*         [          false\n*[         [          false\n*[         a[        false\n----------------------\n\nI 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.\nHowever, it looks like Git simply gives up on parsing the rule, probably because it contains unmatched '[' character starting a (broken) character group.\n\nNext, the surprising table for ']':\n----------------------\nrule  | file | match?\n----------------------\n]           ]          true\n]*         ]          true\n*]         ]          true\n*]         a]        true\n----------------------\n\nHere 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.\nWhy?\n\nIf Git interprets [ character only as part of the glob rules (character groups), it should interpret unmatched ] character equally.\nAlso if Git interprets unmatched  ] character literally, why not same behavior for the [ character?\nIMHO the first table for single '[' character is just a bug in Git, and it should be consistent to the ']' table.\n\nAnyway, it would be nice to hear what should be the \"right\" way to interpret the tables above.\n\nBTW the only official documentation I found about ignore rules:\n\nhttps://www.kernel.org/pub/software/scm/git/docs/gitignore.html\nhttp://man7.org/linux/man-pages/man3/fnmatch.3.html\nhttp://man7.org/linux/man-pages/man7/glob.7.html\n\n-- \nKind regards,\ngoogle.com/+AndreyLoskutov\n"},{"id":"270788","messageId":"m2oagotf1d.fsf@linux-m68k.org","threadId":"40435","inReplyTo":"2606743.RipZrg6Xoz@pinguin","subject":"Re: Single brackets matching in .gitignore rules","fromName":"Andreas Schwab","fromEmail":"schwab@linux-m68k.org","sentAt":"2015-09-27T08:58:06Z","receivedAt":"2015-09-27T08:58:06Z","isPatch":false,"sender":{"key":"schwab@linux-m68k.org","avatar":"https://avatars.githubusercontent.com/u/2175493?v=4"},"body":"Andrey Loskutov <loskutov@gmx.de> writes:\n\n> Next, the surprising table for ']':\n> ----------------------\n> rule  | file | match?\n> ----------------------\n> ]           ]          true\n> ]*         ]          true\n> *]         ]          true\n> *]         a]        true\n> ----------------------\n>\n> 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.\n> Why?\n\n] by itself is not special in a glob.\n\nAndreas.\n\n-- \nAndreas Schwab, schwab@linux-m68k.org\nGPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5\n\"And now for something completely different.\"\n"},{"id":"270797","messageId":"2578959.p0AHc2Ulk9@pinguin","threadId":"40435","inReplyTo":"m2oagotf1d.fsf@linux-m68k.org","subject":"Re: Single brackets matching in .gitignore rules","fromName":"Andrey Loskutov","fromEmail":"loskutov@gmx.de","sentAt":"2015-09-27T16:35:11Z","receivedAt":"2015-09-27T16:35:11Z","isPatch":false,"sender":{"key":"loskutov@gmx.de","avatar":"https://gravatar.com/avatar/3e41c7c1fe4dc85cfdccfa6ab6d1be5b6ba0c0611245e1fc7aedc6e9d77b76ab?d=mp&s=160"},"body":"On Sunday 27 September 2015 10:58 Andreas Schwab wrote:\n> \n> ] by itself is not special in a glob.\n> \n> Andreas.\n> \n\nOK, this would explain the current state: once Git sees opened bracket, it always tries to parse the glob pattern and if this fails (if the bracket is not closed), the ignore rule does not match anything. This does not happen for closing bracket and therefore the difference in behavior.\n\nThanks!\n\nP.S.\nIn case anyone is interested, here is the path for JGit: https://git.eclipse.org/r/#/c/56773/4\n\n-- \nKind regards,\ngoogle.com/+AndreyLoskutov\n"},{"id":"270811","messageId":"CACsJy8DiTevhSnkkab-kfvpibitoUMHdjC2UdGT244JwLRxqWQ@mail.gmail.com","threadId":"40435","inReplyTo":"2606743.RipZrg6Xoz@pinguin","subject":"Re: Single brackets matching in .gitignore rules","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2015-09-28T13:15:53Z","receivedAt":"2015-09-28T13:15:53Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Sun, Sep 27, 2015 at 5:01 AM, Andrey Loskutov <loskutov@gmx.de> wrote:\n> ...\n> Anyway, it would be nice to hear what should be the \"right\" way to interpret the tables above.\n>\n> BTW the only official documentation I found about ignore rules:\n>\n> https://www.kernel.org/pub/software/scm/git/docs/gitignore.html\n> http://man7.org/linux/man-pages/man3/fnmatch.3.html\n> http://man7.org/linux/man-pages/man7/glob.7.html\n\nThis is already answered. I just want to add that C Git has stopped\nusing system fnmatch for some time (part of the reason is system\nfnmatch behaves differently in corner cases). If you don't mind C,\nhave a look at dowild() in wildmatch.c, or t/t3070-wildmatch.sh for\nsome corner cases (but your cases aren't there, may be worth adding\ntoo)\n--\nDuy\n"},{"id":"270822","messageId":"xmqq7fnae92a.fsf@gitster.mtv.corp.google.com","threadId":"40435","inReplyTo":"CACsJy8DiTevhSnkkab-kfvpibitoUMHdjC2UdGT244JwLRxqWQ@mail.gmail.com","subject":"Re: Single brackets matching in .gitignore rules","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-09-28T17:40:45Z","receivedAt":"2015-09-28T17:40:45Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Duy Nguyen <pclouds@gmail.com> writes:\n\n> This is already answered. I just want to add that C Git has stopped\n> using system fnmatch for some time (part of the reason is system\n> fnmatch behaves differently in corner cases). If you don't mind C,\n> have a look at dowild() in wildmatch.c, or t/t3070-wildmatch.sh for\n> some corner cases (but your cases aren't there, may be worth adding\n> too)\n\nWhat exactly are you suggesting to \"fix\", though?  Barf when an\nunmatched ] appears as a part of the pattern, instead of taking it\nliterally?\n"},{"id":"270824","messageId":"4259524.1vtm9ffbuH@pinguin","threadId":"40435","inReplyTo":"xmqq7fnae92a.fsf@gitster.mtv.corp.google.com","subject":"Re: Single brackets matching in .gitignore rules","fromName":"Andrey Loskutov","fromEmail":"loskutov@gmx.de","sentAt":"2015-09-28T17:46:10Z","receivedAt":"2015-09-28T17:46:10Z","isPatch":false,"sender":{"key":"loskutov@gmx.de","avatar":"https://gravatar.com/avatar/3e41c7c1fe4dc85cfdccfa6ab6d1be5b6ba0c0611245e1fc7aedc6e9d77b76ab?d=mp&s=160"},"body":"On Monday 28 September 2015 10:40 Junio C Hamano wrote:\n> Duy Nguyen <pclouds@gmail.com> writes:\n> \n> > This is already answered. I just want to add that C Git has stopped\n> > using system fnmatch for some time (part of the reason is system\n> > fnmatch behaves differently in corner cases). If you don't mind C,\n> > have a look at dowild() in wildmatch.c, or t/t3070-wildmatch.sh for\n> > some corner cases (but your cases aren't there, may be worth adding\n> > too)\n> \n> What exactly are you suggesting to \"fix\", though?  Barf when an\n> unmatched ] appears as a part of the pattern, instead of taking it\n> literally?\n\nI would rather treat the opened but unmatched [ bracket literally, so that it works similar like ]. \nOriginally I've implemented this \"symmetrical\" behavior in JGit without to know that unmatched [ and ] have different behavior in C Git.\n\n-- \nKind regards,\ngoogle.com/+AndreyLoskutov\n"},{"id":"270826","messageId":"xmqqy4fqctdt.fsf@gitster.mtv.corp.google.com","threadId":"40435","inReplyTo":"4259524.1vtm9ffbuH@pinguin","subject":"Re: Single brackets matching in .gitignore rules","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-09-28T18:04:46Z","receivedAt":"2015-09-28T18:04:46Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Andrey Loskutov <loskutov@gmx.de> writes:\n\n> On Monday 28 September 2015 10:40 Junio C Hamano wrote:\n>> Duy Nguyen <pclouds@gmail.com> writes:\n>> \n>> > This is already answered. I just want to add that C Git has stopped\n>> > using system fnmatch for some time (part of the reason is system\n>> > fnmatch behaves differently in corner cases). If you don't mind C,\n>> > have a look at dowild() in wildmatch.c, or t/t3070-wildmatch.sh for\n>> > some corner cases (but your cases aren't there, may be worth adding\n>> > too)\n>> \n>> What exactly are you suggesting to \"fix\", though?  Barf when an\n>> unmatched ] appears as a part of the pattern, instead of taking it\n>> literally?\n>\n> I would rather treat the opened but unmatched [ bracket literally, so\n> that it works similar like ].\n\nAh, OK.  As long as the (broken) pattern '[' has never been\naccepted, it is safe to assume that no working .gitignore file\npeople have should contain such a string and relying that it\ndoes not match anything, I guess.\n"}]}