{"thread":{"id":"41332","subject":"git grep argument parser bug","startedAt":"2016-02-04T22:02:52Z","lastAt":"2016-02-05T00:22:05Z","messageCount":3,"participants":["Dylan Grafmyre","Junio C Hamano","Duy Nguyen"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"277466","messageId":"CANzEV58SgS6P_qBequGSfA0vFy9s0-KM3xOFaU2DDz_S3OyN3g@mail.gmail.com","threadId":"41332","inReplyTo":null,"subject":"git grep argument parser bug","fromName":"Dylan Grafmyre","fromEmail":"dylang@conversica.com","sentAt":"2016-02-04T22:02:52Z","receivedAt":"2016-02-04T22:02:52Z","isPatch":false,"sender":{"key":"dylang@conversica.com","avatar":null},"body":"In both ubuntu versions of git 1.9.1 and 2.7.0\n\n    git grep '-test'\n    git grep '--help'\n\nOr any other expressions literal leading with a single dash or double\ndash get interpreted as argument flags and not as search expressions.\n\nWhat I expect is grep results for the literal strings \"-test\" and \"--help\"\nWhat i get is git help output informing of wrong argument usage, or\naccidentally turning on flags I didn't expect.\n\nWork around; for afflicted users terminating argument parsing with `\n-- ` works as it should.\n\n    git grep -- '-test'\n\nConfirmed on two Ubuntu [based] systems, Ubuntu Server 14.03 and\nLinuxMint 17.3 [Cinnamon]\n\n-- \nDylan Grafmyre\nAssociate System Administrator\n\nEmail: DylanG@conversica.com\nOffice: +1 (888) 778 1004\nWeb:   www.conversica.com\n"},{"id":"277477","messageId":"xmqqzivgf7c6.fsf@gitster.mtv.corp.google.com","threadId":"41332","inReplyTo":"CANzEV58SgS6P_qBequGSfA0vFy9s0-KM3xOFaU2DDz_S3OyN3g@mail.gmail.com","subject":"Re: git grep argument parser bug","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-02-04T22:18:01Z","receivedAt":"2016-02-04T22:18:01Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Dylan Grafmyre <dylang@conversica.com> writes:\n\n> In both ubuntu versions of git 1.9.1 and 2.7.0\n>\n>     git grep '-test'\n>     git grep '--help'\n>\n> Or any other expressions literal leading with a single dash or double\n> dash get interpreted as argument flags and not as search expressions.\n> ...\n> What I expect is grep results for the literal strings \"-test\" and \"--help\"\n\nI think you'd need to adjust your expectations, then ;-).\n\nThis is how \"grep\" (not \"git grep\") works, and you use \"-e\", i.e.\n\n\tgrep -e \"-anything that begins with a dash\" FILES...\n\nto disambiguate.  If you are scripting, if you do not know what you\nhave in a variable, and if you are looking for the value in that\nvariable, you would always do\n\n\tgrep -e \"$variable\" FILES...\n\nnot\n\n        grep \"$variable\" FILES...\n\nI think all of the above is pretty much the standard practice and\n\"git grep\" merely follows suit, i.e.\n\n\tgit grep -e \"-help\"\n\nis designed to work that way to match users' expectations.\n"},{"id":"277498","messageId":"CACsJy8DCn9z2hbodqFw7bL=JDwV8LfFiv52Bk__UO5y8nfcm-A@mail.gmail.com","threadId":"41332","inReplyTo":"CANzEV58SgS6P_qBequGSfA0vFy9s0-KM3xOFaU2DDz_S3OyN3g@mail.gmail.com","subject":"Re: git grep argument parser bug","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2016-02-05T00:22:05Z","receivedAt":"2016-02-05T00:22:05Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Fri, Feb 5, 2016 at 5:02 AM, Dylan Grafmyre <dylang@conversica.com> wrote:\n> In both ubuntu versions of git 1.9.1 and 2.7.0\n>\n>     git grep '-test'\n>     git grep '--help'\n\n(Un)Quoting is done by shell and stripped out before \"git\" is\nexecuted. We just don't see them.\n\n> Or any other expressions literal leading with a single dash or double\n> dash get interpreted as argument flags and not as search expressions.\n>\n> What I expect is grep results for the literal strings \"-test\" and \"--help\"\n> What i get is git help output informing of wrong argument usage, or\n> accidentally turning on flags I didn't expect.\n>\n> Work around; for afflicted users terminating argument parsing with `\n> -- ` works as it should.\n>\n>     git grep -- '-test'\n\nOr you can do \"git grep -e --test\". UNIX grep faces the same problem,\nand also has -e to deal with it.\n\n> Confirmed on two Ubuntu [based] systems, Ubuntu Server 14.03 and\n> LinuxMint 17.3 [Cinnamon]\n-- \nDuy\n"}]}