# Disallow empty pattern in "git grep"

2 messages from 2005-11-16 to 2005-11-16. Participants: Linus Torvalds, Junio C Hamano.
Thread: https://gitlist.dev/t/2555

## Linus Torvalds, 2005-11-16 17:38

Subject: Disallow empty pattern in "git grep"
Message-ID: <Pine.LNX.4.64.0511160934480.13959@g5.osdl.org>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0511160934480.13959%40g5.osdl.org

```

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"

```

## Junio C Hamano, 2005-11-16 21:18

Subject: Re: Disallow empty pattern in "git grep"
Message-ID: <7vr79g47gl.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vr79g47gl.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <Pine.LNX.4.64.0511160934480.13959@g5.osdl.org>

```
Linus Torvalds <torvalds@osdl.org> writes:

> Yeah, maybe we should allow an empty pattern, and just check the number of 
> arguments instead.

I think this patch is OK; I do not see a reason for wanting an
empty pattern.

```
