* Disallow empty pattern in "git grep"
@ 2005-11-16 17:38 Linus Torvalds
2005-11-16 21:18 ` Junio C Hamano
0 siblings, 1 reply; 2+ messages in thread
From: Linus Torvalds @ 2005-11-16 17:38 UTC (permalink / raw)
To: Junio C Hamano, Git Mailing List
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"
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-11-16 21:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-11-16 17:38 Disallow empty pattern in "git grep" Linus Torvalds
2005-11-16 21:18 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox