Skip to contentSkip to conversation

git-grep --relative: show pathnames relative to the current directory

PATCH In review Junio C Hamano 3 participants 3 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 git-grep --relative: show pathnames relative to the current directory

By default, the command shows pathnames relative to the project root, even when run from a subdirectory. With --relative flag, however, the command outputs pathnames relative to the current directory.

This makes it very pleasant to run in Emacs compilation (or "grep-find") buffer.

---

* Now the question is, shouldn't this be the default, with the current output available as an option --full-name, just like ls-files?

Changing the default always risks breaking people's habit and scripts, but I tend to think the current output is a misfeature which we'd better fix sooner rather than later.

Opinions?

 Documentation/git-grep.txt |    7 +++++
 builtin-grep.c             |   58 ++++++++++++++++++++++++++++++++++++--------
 2 files changed, 54 insertions(+), 11 deletions(-)
Documentation/git-grep.txt +6 -1
index dc76833..6cdc433 100644
@@ -11,7 +11,7 @@ SYNOPSIS
 [verse]
 'git-grep' [--cached]
 	   [-a | --text] [-I] [-i | --ignore-case] [-w | --word-regexp]
-	   [-v | --invert-match]
+	   [-v | --invert-match] [--relative]
 	   [-E | --extended-regexp] [-G | --basic-regexp] [-F | --fixed-strings]
 	   [-n] [-l | --files-with-matches] [-L | --files-without-match]
 	   [-c | --count]
@@ -47,6 +47,11 @@ OPTIONS
 -v | --invert-match::
 	Select non-matching lines.
 
+--relative::
+	When run from a subdirectory, show filenames relative to
+	the current directory, instead of the usual full
+	pathname down from the project root.
+
 -E | --extended-regexp | -G | --basic-regexp::
 	Use POSIX extended/basic regexp for patterns.  Default
 	is to use basic regexp.
builtin-grep.c +48 -10

144 lines not on this page · raw message

Signature · 1 line
1.4.2.rc4.g9d8df
#1 lore raw
Quoted 7 lines · Junio C Hamano

By default, the command shows pathnames relative to the project root, even when run from a subdirectory. With --relative flag, however, the command outputs pathnames relative to the current directory.

This makes it very pleasant to run in Emacs compilation (or "grep-find") buffer.

[...]

Quoted 7 lines

* Now the question is, shouldn't this be the default, with the current output available as an option --full-name, just like ls-files?

Changing the default always risks breaking people's habit and scripts, but I tend to think the current output is a misfeature which we'd better fix sooner rather than later.

I think this behavior should be the default, precisely because it otherwise breaks the habits formed during use of plain "grep".

Signature · 2 lines
Karl Hasselström, [email protected]
      www.treskal.com/kalle
#2 lore raw
In reply to Junio C Hamano
Quoted 15 lines · Junio C Hamano

By default, the command shows pathnames relative to the project root, even when run from a subdirectory. With --relative flag, however, the command outputs pathnames relative to the current directory.

This makes it very pleasant to run in Emacs compilation (or "grep-find") buffer.

---

* Now the question is, shouldn't this be the default, with the current output available as an option --full-name, just like ls-files?

Quoted 5 lines

Changing the default always risks breaking people's habit and scripts, but I tend to think the current output is a misfeature which we'd better fix sooner rather than later.

Opinions?

I always felt confused when path was relative to root of .git directory and not relative to current directory.
But I never looked into changing this or reporting it - so it has not been a big issue.

Sam