Subject: bug#17763: closed (Re: bug#17763: grep --exclude does not match files as documented in man page)

From: [email-masked] (GNU bug Tracking System)
Date: Fri, 11 Jul 2014 20:25:03 +0000

Your bug report

#17763: grep --exclude does not match files as documented in man page

which was filed against the grep package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
17763: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=17763
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#17763: grep --exclude does not match files as documented in man page
From: Paul Eggert <[email-masked]>
To: ANDREUX Hugues <[email-masked]>, [email-masked]
Date: Fri, 11 Jul 2014 13:23:56 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

On 06/12/2014 05:05 AM, ANDREUX Hugues wrote:
> According to the man page:
> "       --exclude=GLOB
>                Skip files whose*base name*  matches GLOB (using wildcard matching).

Thanks, I think that's a bug in the documentation, not in the code; 
grep's behavior is similar to that of tar's, which has similar options.  
I installed the attached documentation patch.
>From a279045bf933f45f2c78fd424ef832b688920a40 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Fri, 11 Jul 2014 13:21:19 -0700
Subject: [PATCH] doc: Document -r vs --exclude more carefully.

Problem reported by Hugues Andreux in: http://bugs.gnu.org/17763
* doc/grep.texi (File and Directory Selection): Be more careful
about documenting the interaction between recursive searching,
--include, --exclude, and --exclude-dir.
---
 doc/grep.texi | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/doc/grep.texi b/doc/grep.texi
index 6c484d6..0115560 100644
--- a/doc/grep.texi
+++ b/doc/grep.texi
@@ -651,9 +651,10 @@ this is equivalent to the @option{-r} option.
 @opindex --exclude
 @cindex exclude files
 @cindex searching directory trees
-Skip files whose base name matches @var{glob}
-(using wildcard matching).
-A file-name glob can use
+Skip files whose name matches the pattern @var{glob}, using wildcard
+matching.  When searching recursively, skip any subfile whose base
+name matches @var{glob}; the base name is the part after the last
+@samp{/}.  A pattern can use
 @samp{*}, @samp{?}, and @samp{[}...@samp{]} as wildcards,
 and @code{\} to quote a wildcard or backslash character literally.
 
@@ -661,15 +662,16 @@ and @code{\} to quote a wildcard or backslash character literally.
 @opindex --exclude-from
 @cindex exclude files
 @cindex searching directory trees
-Skip files whose base name matches any of the file-name globs
+Skip files whose name matches any of the patterns
 read from @var{file} (using wildcard matching as described
 under @option{--exclude}).
 
-@item --exclude-dir=@var{dir}
+@item --exclude-dir=@var{glob}
 @opindex --exclude-dir
 @cindex exclude directories
-Skip any directory whose name matches the pattern @var{dir}, ignoring
-any redundant trailing slashes in @var{dir}.
+Skip any directory whose name matches the pattern @var{glob}.  When
+searching recursively, skip any subdirectory whose base name matches
+@var{glob}.  Ignore any redundant trailing slashes in @var{glob}.
 
 @item -I
 Process a binary file as if it did not contain matching data;
@@ -679,8 +681,8 @@ this is equivalent to the @samp{--binary-files=without-match} option.
 @opindex --include
 @cindex include files
 @cindex searching directory trees
-Search only files whose base name matches @var{glob}
-(using wildcard matching as described under @option{--exclude}).
+Search only files whose name matches @var{glob},
+using wildcard matching as described under @option{--exclude}.
 
 @item -r
 @itemx --recursive
-- 
1.9.3

Subject: grep --exclude does not match files as documented in man page
From: ANDREUX Hugues <[email-masked]>
To: "[email-masked]" <[email-masked]>
Date: Thu, 12 Jun 2014 12:05:52 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

It seems file globbing as done by 'grep --exclude' is broken when wildcards are used.

$ echo foo >bar
$ grep --exclude='.*' . ./bar
$ grep --exclude='.*' . bar
foo

Expected behavior: grep -exclude should not exclude bar, whether it is prefixed by ./ or not. According to the man page:
"       --exclude=GLOB
              Skip files whose *base name* matches GLOB (using wildcard matching). [...]"

This behavior seems to only occur with whenever a directory component of the file path matches the GLOB, e.g.:
$ grep --exclude '.*' . ../bar
$ grep --exclude '.*' . .../bar
$ grep --exclude '.*' . .TEST/bar
$ grep --exclude '.*' . hugues/.TEST/bar

The bug triggers with other globs, unless there is no wildcard:
$ grep --exclude 'w*' . work/bar
$ grep --exclude 'work' . work/bar
foo

Regards,

Hugues Andreux
*************************************************************************
This message and any attachments (the "message") are confidential, intended solely for the addressee(s), and may contain legally privileged information.
Any unauthorised use or dissemination is prohibited. E-mails are susceptible to alteration.   
Neither SOCIETE GENERALE nor any of its subsidiaries or affiliates shall be liable for the message if altered, changed or
falsified.
Please visit http://swapdisclosure.sgcib.com for important information with respect to derivative products.
                              ************
Ce message et toutes les pieces jointes (ci-apres le "message") sont confidentiels et susceptibles de contenir des informations couvertes 
par le secret professionnel. 
Ce message est etabli a l'intention exclusive de ses destinataires. Toute utilisation ou diffusion non autorisee est interdite.
Tout message electronique est susceptible d'alteration. 
La SOCIETE GENERALE et ses filiales declinent toute responsabilite au titre de ce message s'il a ete altere, deforme ou falsifie.
Veuillez consulter le site http://swapdisclosure.sgcib.com afin de recueillir d'importantes informations sur les produits derives.
*************************************************************************