Thanks for catching that! Here's a proposed patch that adds a test case for this.
>From 7b5b17d22b223994b8f439b494b25bbd3c6f85e8 Mon Sep 17 00:00:00 2001 From: Paul Eggert <[email protected]> Date: Sun, 11 Mar 2012 19:02:34 -0700 Subject: [PATCH] grep: fix bug with -r --exclude-dir and no file operand Reported by Allan McRae in <http://lists.gnu.org/archive/html/bug-grep/2012-03/msg00032.html>. * src/main.c (grepdir): Don't invoke excluded_file_name on NULL. * tests/include-exclude: Test for the bug and fix. --- src/main.c | 2 +- tests/include-exclude | 4 ++++ 2 files changed, 5 insertions(+), 1 deletions(-) diff --git a/src/main.c b/src/main.c index 2f6c761..f4f1235 100644 --- a/src/main.c +++ b/src/main.c @@ -1361,7 +1361,7 @@ grepdir (char const *dir, struct stats const *stats) struct stats const *ancestor; char *name_space; int status = 1; - if (excluded_directory_patterns + if (dir && excluded_directory_patterns && excluded_file_name (excluded_directory_patterns, dir)) return 1; diff --git a/tests/include-exclude b/tests/include-exclude index 1093de9..406e0d4 100755 --- a/tests/include-exclude +++ b/tests/include-exclude @@ -12,6 +12,7 @@ printf '%s\n' x/dir/d:ddd > exp-not-ab || framework_failure_ printf '%s\n' x/a:aaa x/b:bbb > exp-not-d || framework_failure_ printf '%s\n' x/a:aaa x/b:bbb > exp-not-dir || framework_failure_ printf '%s\n' x/a:aaa > exp-a || framework_failure_ +printf '%s\n' a:aaa > exp-aa || framework_failure_ printf '%s\n' aaa > exp-aaa || framework_failure_ grep -r --exclude='a*' . x > out || fail=1 @@ -44,6 +45,9 @@ compare exp-a out || fail=1 grep --directories=skip --include=a --exclude-dir=dir '^aaa$' x/* > out || fail=1 compare exp-a out || fail=1 +(cd x && grep -r --exclude-dir=. '^aaa$') > out || fail=1 +compare exp-aa out || fail=1 + grep --exclude=- '^aaa$' - < x/a > out || fail=1 compare exp-aaa out || fail=1 -- 1.7.6.5
