git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git grep argument parser bug

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 4, 2016, 22:18 UTC
Message-ID
<xmqqzivgf7c6.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<CANzEV58SgS6P_qBequGSfA0vFy9s0-KM3xOFaU2DDz_S3OyN3g@mail.gmail.com>
Dylan Grafmyre <dylang@conversica.com> writes:
Show 9 quoted lines
> In both ubuntu versions of git 1.9.1 and 2.7.0
>
>     git grep '-test'
>     git grep '--help'
>
> Or any other expressions literal leading with a single dash or double
> dash get interpreted as argument flags and not as search expressions.
> ...
> What I expect is grep results for the literal strings "-test" and "--help"
I think you'd need to adjust your expectations, then ;-).
This is how "grep" (not "git grep") works, and you use "-e", i.e.
	grep -e "-anything that begins with a dash" FILES...

to disambiguate. If you are scripting, if you do not know what you have in a variable, and if you are looking for the value in that variable, you would always do

	grep -e "$variable" FILES...
not
        grep "$variable" FILES...

I think all of the above is pretty much the standard practice and "git grep" merely follows suit, i.e.

	git grep -e "-help"
is designed to work that way to match users' expectations.
Previous: Dylan GrafmyreNext: Duy Nguyen
Message 2 of 3 in “git grep argument parser bug”
  1. Dylan GrafmyreFeb 4, 2016
  2. Junio C HamanoFeb 4, 2016
  3. Duy NguyenFeb 5, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.