Disallow empty pattern in "git grep"

From: Linus Torvalds <torvalds@osdl.org>
Date: 2016-06-15 22:42:12
Subsystem: the rest · Maintainer: Linus Torvalds

For some reason I've done a "git grep" twice with no pattern, which is 
really irritating, since it just grep everything. If I actually wanted 
that, I could do "git grep ^" or something.

So add a "usage" message if the pattern is empty.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---

Yeah, maybe we should allow an empty pattern, and just check the number of 
arguments instead. However, the argument parsing isn't set up that way, so 
this was the simple and ugly approach.

So this will warn even for

	git grep ""

which might be otherwise be considered legal (but stupid).
diff --git a/git-grep.sh b/git-grep.sh
index e7a35eb..44c1613 100755
--- a/git-grep.sh
+++ b/git-grep.sh
@@ -39,5 +39,9 @@ while : ; do
 	esac
 	shift
 done
+[ "$pattern" ] || {
+	echo >&2 "usage: 'git grep <pattern> [pathspec*]'"
+	exit 1
+}
 git-ls-files -z "${git_flags[@]}" "$@" |
 	xargs -0 grep "${flags[@]}" -e "$pattern"
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help