Hi Duy, Nguyễn Thái Ngọc Duy wrote: > Subject: [PATCH] t7002: test git grep --no-index from a bare repository It’s t7810 now (to keep t7811 company). > There is an interesting thing about this command. Back in tp/setup > series, there is a patch that changes the current behavior, > "calculate prefix even if no worktree is found". grep is interesting > because it depends on the current behavior, i.e. prefix being NULL > in bare repo, while it still needs true prefix to do chdir() > stuff in run_pager(). Yes, sorry to let this hang for so long. I liked your setup series for many reasons and am happy to see pieces of it coming back to life. > +++ b/Documentation/git-grep.txt > @@ -28,8 +28,9 @@ SYNOPSIS > DESCRIPTION > ----------- > Look for specified patterns in the tracked files in the work tree, blobs > -registered in the index file, or blobs in given tree objects. > - > +registered in the index file, or blobs in given tree objects. By default > +it will only search tracked files within the current directory (or full > +tree if in bare repository). Probably deserves more detail. Searches for lines matching the specified patterns in the work tree, the index, or a specified tree. By default, 'git grep' only examines tracked files in the subtree of the work tree rooted at the current working directory. Output consists of matching lines preceded with the corresponding filename and a colon. With `--cached`, 'git grep' does the same search in the version scheduled for the next commit in the index. With `--no-index`, 'git grep' pays no mind to the index file and reports *all* matching files under the working directory. Given a commit name, 'git grep' does the same search in that historical version. More generally, given a tree name, 'git grep' searches the subtree of that tree object corresponding to the path to the current directory from the root of the work tree (or the entire tree if there is no work tree, as in a bare repository). > > OPTIONS > ------- > diff --git a/builtin/grep.c b/builtin/grep.c > index 597f76b..e8abdc7 100644 > --- a/builtin/grep.c > +++ b/builtin/grep.c > @@ -1109,6 +1109,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix) > > if (use_threads) > hit |= wait_all(); > + > + /* FIXME prefix is NULL in bare repo, no matter where cwd is */ > if (hit && show_in_pager) > run_pager(&opt, prefix); This comment seems kind of unhelpful. Maybe something like /* * NOTE NOTE NOTE: Even in a bare repository, the user * probably expected the command specified with -O to run in * the current directory, but when --no-index is supplied, we * are passing it paths relative to the .git directory. * Until that changes, this needs not to chdir() in that case. */ Do I understand correctly? -- 8< -- Subject: grep documentation: flesh out description As Duy noticed, it is not always obvious what directory ‘git grep’ is going to search in. Add some other details to the description, too. Inspired by http://gitster.livejournal.com/27674.html Cc: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> Signed-off-by: Jonathan Nieder <jrnieder@xxxxxxxxx> --- Documentation/git-grep.txt | 21 +++++++++++++++++++-- 1 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt index 5474dd7..d6cfbc6 100644 --- a/Documentation/git-grep.txt +++ b/Documentation/git-grep.txt @@ -27,9 +27,26 @@ SYNOPSIS DESCRIPTION ----------- -Look for specified patterns in the tracked files in the work tree, blobs -registered in the index file, or blobs in given tree objects. - +Searches for lines matching the specified patterns in the work +tree, the index, or the specified tree objects. + +By default, 'git grep' only examines tracked files in the subtree +of the work tree rooted at the current working directory. Output +consists of matching lines preceded with the corresponding +filename and a colon. + +With `--cached`, 'git grep' does the same search in the version +scheduled for the next commit in the index. + +With `--no-index`, 'git grep' pays no mind to the index file and +reports *all* matching files under the working directory. + +When passed a commit name, 'git grep' does the same search but in +that historical version. More generally, given a tree name, +'git grep' searches the subtree of that tree object corresponding +to the path to the current directory from the root of the work tree +(or the entire tree if there is no work tree, as in a bare +repository). OPTIONS ------- -- 1.7.2.rc3 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html