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

Re: "git grep" and "working tree" vs "working directory"

From
Stefan Beller <sbeller@google.com>
Date
May 24, 2018, 20:50 UTC
Message-ID
<CAGZ79kavmH5KVS2Byc5+Hg3dOvVwGD11KZ3yzZTLwp8Ok9ZDTg@mail.gmail.com>
In-Reply-To
<alpine.LFD.2.21.1805231434010.28811@localhost.localdomain>

On Wed, May 23, 2018 at 11:50 AM, Robert P. J. Day <rpjday@crashcourse.ca> wrote:

Show 13 quoted lines
>
>   more puzzling terminology, this time in the man page for "git grep".
> the SYNOPSIS shows, at the very end, the clearly optional
> "[<pathspec>...]",
>
>     git grep ...
>            ... snip ...
>            [--] [<pathspec>...]
>
> but nowhere in the man page is there an explanation as to the default
> value used if there is no pathspec, and here's why that's confusing.
>
>   first, what is the proper phrase for the *entire* checked out repo?

What is the *entirety* of a checked out repo? (Is it just the main working tree, or do you mean all directories that are found "git worktree --list" ?)

http://public-inbox.org/git/xmqqo9wy4hxa.fsf@gitster.mtv.corp.google.com gives insights into "worktree vs working tree", the former being the command and the latter being the directory you work in -- a working directory if you will -- but the terminology is working tree. There was another recent discussion on that, why it stuck with "tree".

Show 34 quoted lines
> working tree? working directory? either? and is that the proper phrase
> to use *regardless* of where you happen to be located, perhaps in a
> subdirectory?
>
>   i did a quick test and, if i don't supply a pathspec, then "git
> grep" (quite reasonably) recursively searches only the *current*
> working directory (example from linux kernel source repo):
>
>   $ cd scripts
>   $ git grep -il torvalds --
>   checkstack.pl
>   get_maintainer.pl
>   package/mkdebian
>   $
>
> however, if you peruse the very first part of the OPTIONS section of
> that man page, you read:
>
>   --cached
>       Instead of searching tracked files in the working tree,
>       search blobs registered in the index file.
>
>   --no-index
>       Search files in the current directory that is not managed by Git.
>
>   --untracked
>       In addition to searching in the tracked files in the
>       working tree, search also in untracked files.
>
>   ... snip ...
>
> note how a couple of those options are described as searching "the
> working tree", when they clearly(?) do no such thing if you happen to
> be located in a subdirectory.
There are 2 dimensions to it:
* (where you are)
  if you run git-grep from a sub directory of the repository, then the
"sub-working-tree"
  will be searched. Extend the example from above by calling
  cd scripts
  git rm --cached checkstack.pl
  git grep -il torvalds --
  ls   checkstack.pl
* (what is searched)
  The options mentioned above specify what exactly is used as the base
for searching
  (the file system, the index, or a commit)
Show 10 quoted lines
>   also, at the bottom of that section, one reads:
>
>   <pathspec>...
>       If given, limit the search to paths matching at least one
>       pattern. Both leading paths match and glob(7) patterns are supported.
>
>       For more details about the <pathspec> syntax, see the pathspec
>       entry in gitglossary(7).
>
> but, again, what if <pathspec> is *not* given? then what?
Assume "$pwd/."
Show 10 quoted lines
>
>   finally, the first example has the same problem:
>
>   git grep 'time_t' -- '*.[ch]'
>       Looks for time_t in all tracked .c and .h files in the
>       working directory and its subdirectories.
>
> in "the working directory"?
>
>   what is the proper terminology to be used here?

the working directory sounds right, not sure which aspect you want to be exposed more clearly.

Previous: Robert P. J. DayNext: Junio C Hamano
Message 2 of 4 in “"git grep" and "working tree" vs "working directory"”
  1. Robert P. J. DayMay 23, 2018
  2. Stefan BellerMay 24, 2018
  3. Junio C HamanoMay 25, 2018
  4. Robert P. J. DayMay 25, 2018

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.