From: Linus Torvalds Date: Wed, 16 Nov 2005 17:38:46 GMT Subject: Disallow empty pattern in "git grep" Message-ID: 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 --- 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 [pathspec*]'" + exit 1 +} git-ls-files -z "${git_flags[@]}" "$@" | xargs -0 grep "${flags[@]}" -e "$pattern"