I pushed the attached patch to fix this. Thanks again for reporting the problem.
From aa17882425c882ce8142f5f15880aa238c1fa855 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Sat, 24 May 2014 14:06:29 -0700
Subject: [PATCH] grep: --exclude-dir=FOO/ now ignores the trailing slash

Problem reported by Khaled Ziyaeen; see: http://bugs.gnu.org/17481
* NEWS, doc/grep.texi (File and Directory Selection): Document this.
* src/grep.c (main): Implement this.
* tests/include-exclude: Test this.
---
 NEWS                  | 5 +++++
 doc/grep.texi         | 4 ++--
 src/grep.c            | 1 +
 tests/include-exclude | 4 ++++
 4 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index bf31940..10b2d19 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,11 @@ GNU grep NEWS                                    -*- outline 
-*-
 
 * Noteworthy changes in release ?.? (????-??-??) [?]
 
+** Changes in behavior
+
+  grep --exclude-dir='FOO/' now excludes the directory FOO.
+  Previously, the trailing slash meant the option was ineffective.
+
 
 * Noteworthy changes in release 2.19 (2014-05-22) [stable]
 
diff --git a/doc/grep.texi b/doc/grep.texi
index feee0d8..c9417e5 100644
--- a/doc/grep.texi
+++ b/doc/grep.texi
@@ -668,8 +668,8 @@ under @option{--exclude}).
 @item --exclude-dir=@var{dir}
 @opindex --exclude-dir
 @cindex exclude directories
-Exclude directories matching the pattern @var{dir} from recursive
-directory searches.
+Skip any directory whose name matches the pattern @var{dir}, ignoring
+any redundant trailing slashes in @var{dir}.
 
 @item -I
 Process a binary file as if it did not contain matching data;
diff --git a/src/grep.c b/src/grep.c
index ec955d8..6a2a029 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -2234,6 +2234,7 @@ main (int argc, char **argv)
       case EXCLUDE_DIRECTORY_OPTION:
         if (!excluded_directory_patterns)
           excluded_directory_patterns = new_exclude ();
+        strip_trailing_slashes (optarg);
         add_exclude (excluded_directory_patterns, optarg, EXCLUDE_WILDCARDS);
         break;
 
diff --git a/tests/include-exclude b/tests/include-exclude
index 28465cb..9c07139 100755
--- a/tests/include-exclude
+++ b/tests/include-exclude
@@ -36,6 +36,10 @@ grep -r --exclude-dir=dir . x > out || fail=1
 sort out > k && mv k out
 compare exp-not-dir out || fail=1
 
+grep -r --exclude-dir=dir/ . x > out || fail=1
+sort out > k && mv k out
+compare exp-not-dir out || fail=1
+
 # Test with a non-glob.
 grep -r --include=a    . x > out || fail=1
 # no need to sort
-- 
1.9.0

Reply via email to