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

Re: [PATCH] grep: die gracefully when outside repository

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 15, 2023, 17:57 UTC
Message-ID
<xmqq7cnnpy3z.fsf@gitster.g>
In-Reply-To
<20231015032636.GC554702@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
> Is it even reasonable for "grep --no-index" to care about leaving the
> tree in the first place? That is, is there a reason we should not allow:
>
>   git grep --no-index foo ../bar

A huge difference between the bare "grep" and "git grep" is that we know the scope of the project tree, so it goes recursive by default. Should the above command line recursively go below ../bar? Would we allow "/" to be given?

I actually do not think these "we are allowing Git tools to be used on random garbage" is a good idea to begin with X-<. If we invented something nice for our variant in "git grep" and wish we can use it outside the repository, contributing the feature to implementations of "grep" would have been the right way to move forward, instead of contaminating the codebase with things that are not related to Git. Whoever did 59332d13 (Resurrect "git grep --no-index", 2010-02-06) should be punished X-<.

Anyway.

2e48fcdb (grep docs: document --no-index option, 2010-02-25) seems to have wanted to explicitly limit the search within the "current directory", and I am fine to keep the search space limited by the cwd. On the other hand, of course, the users can shoot themselves in the foot with "grep -r foo /", so letting them use "git grep" the same way is perhaps OK. Especially if it simplifies the code if we lift the limitation, that is a very tempting thing to do.

> If we want to avoid leaving the current directory, then I think we need
> to be checking much sooner (but again, I would argue that it is not
> worth caring about in no-index mode).
Previous: Kristoffer HaugsbakkNext: Junio C Hamano
Message 7 of 15 in “Bug: git grep --no-index 123 /dev/stdin crashes with SIGABRT”
  1. ks1322 ks1322Oct 14, 2023
  2. Kristoffer HaugsbakkOct 14, 2023
  3. Kristoffer HaugsbakkOct 14, 2023
  4. grep: die gracefully when outside repositoryKristoffer Haugsbakk, Oct 14, 2023
  5. Jeff KingOct 15, 2023
  6. Kristoffer HaugsbakkOct 15, 2023
  7. Junio C HamanoOct 15, 2023
  8. Junio C HamanoOct 17, 2023
  9. Kristoffer HaugsbakkOct 17, 2023
  10. Junio C HamanoOct 17, 2023
  11. Junio C HamanoOct 17, 2023
  12. grep: die gracefully when outside repositoryKristoffer Haugsbakk, Oct 20, 2023
  13. Eric SunshineOct 20, 2023
  14. Junio C HamanoOct 20, 2023
  15. grep: die gracefully when outside repositoryKristoffer Haugsbakk, Oct 20, 2023

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.