Subject: bug#45432: Use both --include and --exclude at the same time

From: "Fred .Flintstone" <[email-masked]>
Date: Wed, 6 Jan 2021 21:12:09 +0100

Yes, I meant like Tanaka said, I want BOTH to include AND exclude.
So I can include only a file extension, and exclude certain directories
such as directories containing unit tests and integration tests.

On Tue, Jan 5, 2021 at 2:27 PM Norihiro Tanaka <[email-masked]> wrote:

>
> On Mon, 4 Jan 2021 09:55:48 -0800
> Jim Meyering <[email-masked]> wrote:
>
> > tags 45432 moreinfo
> > stop
> >
> > On Fri, Dec 25, 2020 at 8:57 AM Fred .Flintstone <[email-masked]>
> wrote:
> > > It seems --exclude does nothing when --include is used. It would be
> useful
> > > to be able to use both together, in order to do things such as
> recusively
> > > grepping files of a certain file extension while excluding certain
> > > directories.
> > >
> > > Example:
> > > $ grep --recursive --include="*.cs" --exclude="*/tests/*"
> >
> > Can you provide a complete example showing a malfunction?
> > You've probably already read this from "info grep", but see also
> > the description of --exclude there:
> >
> > ‘--include=GLOB’
> >      Search only files whose name matches GLOB, using wildcard matching
> >      as described under ‘--exclude’.  If contradictory ‘--include’ and
> >      ‘--exclude’ options are given, the last matching one wins.  If no
> >      ‘--include’ or ‘--exclude’ options match, a file is included unless
> >      the first such option is ‘--include’.
>
> I understand as he requests "AND" condition.
>
> $ mkdir a b
> $ touch a/x.a a/x.b b/x.a b/x.b
> $ for file in */*; do echo x >$file; done
>
> Current result:
> $ grep --recursive '--include=*.a' '--exclude=b/*' x .
> ./b/x.a:x
> ./a/x.a:x
>
> Request from him:
> $ grep --recursive '--include=*.a' '--exclude=b/*' x .
> ./a/x.a:x
>
> It means "*.a expept b/*"
>
>