threads / discuss / 38059

git file listing is inconsistent

Subject: git file listing is inconsistent

## tl;dr

5 messages between Nov 26, 2014 and Nov 26, 2014.

replies: 4people: 4as markdown or json

Woody Gilk· Nov 26, 2014, 21:10 UTC · lore

git diff --name-only git grep --files-with-matches

I think --files-with-matches should be deprecated and replaced with --name-only for consistency.

Thanks, -- Woody Gilk http://about.me/shadowhand

Junio C Hamano· Nov 26, 2014, 21:47 UTC · re: Woody Gilk · lore

Re: git file listing is inconsistent

Woody Gilk <woody.gilk@gmail.com> writes:
Show 5 quoted lines
> git diff --name-only
> git grep --files-with-matches
>
> I think --files-with-matches should be deprecated and replaced with
> --name-only for consistency.
That longer name comes from "GNU grep" consistency.

Why anybody does not use a shorter and sweeter "grep -l" is beyond me, though ;-)

Jonathan Nieder· Nov 26, 2014, 21:55 UTC · re: Woody Gilk · lore

Re: git file listing is inconsistent

Hi Woody,
Woody Gilk wrote:
Show 5 quoted lines
> git diff --name-only
> git grep --files-with-matches
>
> I think --files-with-matches should be deprecated and replaced with
> --name-only for consistency.
See the (non-git) diff(1) and grep(1) manpages.

It might make sense for 'git grep' to learn --name-only too as a synonym to help muscle memory, though.

*looks*

Actually, 'git grep -h' tells me that git grep --name-only is already accepted as a synonym for --files-with-matches, ever since

 $ git log -Sname-only -- builtin-grep.c
[...]
 commit 2cd5dfd240ecb63c77bcb2532664984e3b69ae47
 Author: Shawn O. Pearce <spearce@spearce.org>
 Date:   Wed Feb 20 23:28:07 2008 -0500
     Teach git-grep --name-only as synonym for -l
     I expected git grep --name-only to give me only the file names,
     much as git diff --name-only only generates filenames.  Alas the
     option is -l, which matches common external greps but doesn't match
     other parts of the git UI.
     Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
     Signed-off-by: Junio C Hamano <gitster@pobox.com>
(v1.5.5-rc0~171).  Have you tried it?
Would something like the following patch help?
-- >8 --
Subject: grep doc: add reminder about --name-only option

Since v1.5.5-rc0~171 (2008-02-20), "git grep" accepts --name-only as a synonym for the GNU-style --files-with-matches, but because the synonym is not mentioned in the manpage synopsis it is hard to find.

Reported-by: Woody Gilk <woody.gilk@gmail.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 Documentation/git-grep.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt
index 31811f1..8060efe 100644
--- a/Documentation/git-grep.txt
+++ b/Documentation/git-grep.txt
@@ -14,7 +14,7 @@ SYNOPSIS
 	   [-E | --extended-regexp] [-G | --basic-regexp]
 	   [-P | --perl-regexp]
 	   [-F | --fixed-strings] [-n | --line-number]
-	   [-l | --files-with-matches] [-L | --files-without-match]
+	   [-l | --files-with-matches | --name-only] [-L | --files-without-match]
 	   [(-O | --open-files-in-pager) [<pager>]]
 	   [-z | --null]
 	   [-c | --count] [--all-match] [-q | --quiet]
-- 
2.2.0.rc0.207.ga3a616c
Woody Gilk· Nov 26, 2014, 22:01 UTC · re: Jonathan Nieder · lore

Re: git file listing is inconsistent

Jonathan,
On Wed, Nov 26, 2014 at 3:55 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:
> Actually, 'git grep -h' tells me that git grep --name-only is already
> accepted as a synonym for --files-with-matches, ever since

You are absolutely right, it was a typo (and then not RTFM the resulting help) on my part that caused the confusion.

Nothing needs to change here. :) -- Woody Gilk http://about.me/shadowhand

Scott Schmit· Nov 26, 2014, 21:59 UTC · re: Woody Gilk · lore

Re: git file listing is inconsistent

On Wed, Nov 26, 2014 at 03:10:33PM -0600, Woody Gilk wrote:
Show 5 quoted lines
> git diff --name-only
> git grep --files-with-matches
> 
> I think --files-with-matches should be deprecated and replaced with
> --name-only for consistency.

git grep supports both: --name-only for consistency with other git commands, and --files-with-matches for consistency with grep(1).

So I don't think anything needs to change. All we need to do is to teach grep(1) the --name-only option, and the cycle will be complete. [I can never remember grep's version of the option...] :-D

-- 
Scott Schmit

← back to recent threads