{"thread":{"id":"2555","subject":"Disallow empty pattern in \"git grep\"","startedAt":"2005-11-16T17:38:46Z","lastAt":"2005-11-16T21:18:50Z","messageCount":2,"participants":["Linus Torvalds","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"12022","messageId":"Pine.LNX.4.64.0511160934480.13959@g5.osdl.org","threadId":"2555","inReplyTo":null,"subject":"Disallow empty pattern in \"git grep\"","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-11-16T17:38:46Z","receivedAt":"2005-11-16T17:38:46Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nFor some reason I've done a \"git grep\" twice with no pattern, which is \nreally irritating, since it just grep everything. If I actually wanted \nthat, I could do \"git grep ^\" or something.\n\nSo add a \"usage\" message if the pattern is empty.\n\nSigned-off-by: Linus Torvalds <torvalds@osdl.org>\n---\n\nYeah, maybe we should allow an empty pattern, and just check the number of \narguments instead. However, the argument parsing isn't set up that way, so \nthis was the simple and ugly approach.\n\nSo this will warn even for\n\n\tgit grep \"\"\n\nwhich might be otherwise be considered legal (but stupid).\n\ndiff --git a/git-grep.sh b/git-grep.sh\nindex e7a35eb..44c1613 100755\n--- a/git-grep.sh\n+++ b/git-grep.sh\n@@ -39,5 +39,9 @@ while : ; do\n \tesac\n \tshift\n done\n+[ \"$pattern\" ] || {\n+\techo >&2 \"usage: 'git grep <pattern> [pathspec*]'\"\n+\texit 1\n+}\n git-ls-files -z \"${git_flags[@]}\" \"$@\" |\n \txargs -0 grep \"${flags[@]}\" -e \"$pattern\"\n"},{"id":"12049","messageId":"7vr79g47gl.fsf@assigned-by-dhcp.cox.net","threadId":"2555","inReplyTo":"Pine.LNX.4.64.0511160934480.13959@g5.osdl.org","subject":"Re: Disallow empty pattern in \"git grep\"","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-11-16T21:18:50Z","receivedAt":"2005-11-16T21:18:50Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Linus Torvalds <torvalds@osdl.org> writes:\n\n> Yeah, maybe we should allow an empty pattern, and just check the number of \n> arguments instead.\n\nI think this patch is OK; I do not see a reason for wanting an\nempty pattern.\n"}]}