Re: multiple source file extensions
- From
- Mikael Magnusson <mikachu@gmail.com>
- Date
- May 5, 2015, 17:30 UTC
- Message-ID
- <CAHYJk3TzZd8N6E+=nNi1jR36Zc5A7be8ZPL9jLU7c8uAdQJYBw@mail.gmail.com>
- In-Reply-To
- <20150505034336.GA25194@peff.net>
On Tue, May 5, 2015 at 5:43 AM, Jeff King <peff@peff.net> wrote:
Show 32 quoted lines
> On Mon, May 04, 2015 at 07:12:45PM -0300, Thiago Farina wrote:
>
>> On Fri, May 1, 2015 at 10:11 PM, Jeff King <peff@peff.net> wrote:
>> > On Fri, May 01, 2015 at 08:49:14PM -0400, Josh Hagins wrote:
>> >
>> >> If you're using a recent version of bash, you could enable the
>> >> 'globstar' option:
>> >>
>> >> $ shopt -s globstar
>> >> $ git grep 'pattern' **/*.{cc,cpp,h}
>> >>
>> >> Does that work?
>> >
>> > That will only pick up files that are in the working tree. Which is fine
>> > for a stock "git grep" with no options, but would not be right for
>> > grepping in the index or an older tree. For that, you can ask git to
>> > glob for you:
>> >
>> > git grep pattern -- '*.cc' '*.cpp' '*.h'
>> >
>> Is it possible to do a regex like the following?
>>
>> ".*\.[cChH]\(pp\)?"
>
> No, pathspecs are globs, not regexps. I think the idea has been floated
> for supporting regexps, which you would activate something like:
>
> git grep pattern -- :(regexp)$your_regex_here
>
> but nobody has implemented it. I'm not sure it actually saves you any
> typing (besides which, your regexp does not match ".cc", which was in
> the original).Remember that the more bells and whistles you add to pathspecs, the less actual filenames can be conveniently tracked by git; *.c will be expanded by the shell and passed literally to git, and if git then interprets a bunch of stuff again, you could end up with a false negative or positive match. Obviously files with * and ? in them are already unsupported, try not to add more.
-- Mikael Magnusson