mbox series

[0/5] New config option for git-grep to include untracked files

Message ID cover.1710781235.git.dsimic@manjaro.org (mailing list archive)
Headers show
Series New config option for git-grep to include untracked files | expand

Message

Dragan Simic March 18, 2024, 5:03 p.m. UTC
This patch series introduces new config option grep.includeUntracked,
which makes the untracked files also searched by default when git-grep(1)
is invoked, in addition to searching the tracked files.  This is quite
handy when someone expects git-grep(1) to mimic grep(1) even better, when
it comes to the selection of searched files.

Setting grep.includeUntracked to true in one's git configuration should
have no ill effects to various scripts, which presumably shouldn't rely
on expensive operations such as git-grep(1).

This series also performs some related cleanups and small improvements,
which are extracted into separate patches.

Dragan Simic (5):
  grep: perform some minor code and comment cleanups
  grep docs: describe --recurse-submodules further and improve
    formatting a bit
  grep docs: describe --no-index further
  grep: introduce new config option to include untracked files
  grep docs: describe new config option to include untracked files

 Documentation/config/grep.txt |  8 +++++++-
 Documentation/git-grep.txt    | 19 +++++++++++--------
 builtin/grep.c                | 24 +++++++++++-------------
 t/t7810-grep.sh               |  9 +++++++++
 4 files changed, 38 insertions(+), 22 deletions(-)

Comments

Junio C Hamano March 19, 2024, 12:21 a.m. UTC | #1
Dragan Simic <dsimic@manjaro.org> writes:

> This patch series introduces new config option grep.includeUntracked,
> which makes the untracked files also searched by default when git-grep(1)
> is invoked, in addition to searching the tracked files.

Hmph.  I am moderately negative on any configuration that screws
with the default haystack from which needle is sought for.

I may often do "git grep --cached" but that does not mean I would
welcome an configuration option to make "git grep" search in the
index even when the request by the user does not have "--cached".

Inclusion of untracked sources in a sense is even worse, especially
when an unsuspecting "git grep" user (or a script) fully expects
that any paths found in the output are to be found in "git ls-files
-s" output but when you stray into a repository with the
configuration set, that expectation suddelnly gets broken.

So, I dunno.
Dragan Simic March 19, 2024, 5:09 a.m. UTC | #2
Hello Junio,

On 2024-03-19 01:21, Junio C Hamano wrote:
> Dragan Simic <dsimic@manjaro.org> writes:
> 
>> This patch series introduces new config option grep.includeUntracked,
>> which makes the untracked files also searched by default when 
>> git-grep(1)
>> is invoked, in addition to searching the tracked files.
> 
> Hmph.  I am moderately negative on any configuration that screws
> with the default haystack from which needle is sought for.
> 
> I may often do "git grep --cached" but that does not mean I would
> welcome an configuration option to make "git grep" search in the
> index even when the request by the user does not have "--cached".
> 
> Inclusion of untracked sources in a sense is even worse, especially
> when an unsuspecting "git grep" user (or a script) fully expects
> that any paths found in the output are to be found in "git ls-files
> -s" output but when you stray into a repository with the
> configuration set, that expectation suddelnly gets broken.

Hmm...  Those are valid concerns.  For example, I'd also be against
another configuration option that would make it possible to enable
--cached by default, for example, because it could easily mess the
things up really bad.

However, I think that the usability of this new configuration option
outweighs the possible issues it could cause to some users.  For
example, I quite often find myself in need to specify --untracked
while running git-grep(1), to see what's found in the code changes
I haven't staged yet, so I find this new configuration very useful.

Of course, I already have a few aliases defined for grep operations,
but defining another one for "grep --untracked" simply doesn't fit
into my alias scheme.  Obviously, that's why I implemented this new
option, :) hoping that it would be usable to other people, too.

I'm not sure how many users could be affected by the possible negative
effects of this configuration option, by using a specific mix of git
operations, but I think it would be quite useful.
Junio C Hamano March 19, 2024, 5:43 p.m. UTC | #3
Dragan Simic <dsimic@manjaro.org> writes:

> However, I think that the usability of this new configuration option
> outweighs the possible issues it could cause to some users.

"Screw others who share my preference and want to set this variable,
but use third-party tools and scripts that will get broken with this
change, because I do not use them" is what we try not to say around
here.

> For example, I quite often find myself in need to specify
> --untracked while running git-grep(1), to see what's found in the
> code changes I haven't staged yet, so I find this new
> configuration very useful.

The feature (not the command line option, but the behaviour that is
triggered by it) surely may be useful.  Otherwise we wouldn't have
added it.  As I already said, I often find myself doing "--cached".
But that does not make it a good idea to invent a new configuration
variable and set "grep.source=cached".
Dragan Simic March 19, 2024, 5:48 p.m. UTC | #4
On 2024-03-19 18:43, Junio C Hamano wrote:
> Dragan Simic <dsimic@manjaro.org> writes:
> 
>> However, I think that the usability of this new configuration option
>> outweighs the possible issues it could cause to some users.
> 
> "Screw others who share my preference and want to set this variable,
> but use third-party tools and scripts that will get broken with this
> change, because I do not use them" is what we try not to say around
> here.

Well, I didn't mean it that way, but I get your point.  Basically,
this series cannot be merged, so I'll extract the cleanup patches
from it, improve them according to the earlier discussions, and
submit them separately.

>> For example, I quite often find myself in need to specify
>> --untracked while running git-grep(1), to see what's found in the
>> code changes I haven't staged yet, so I find this new
>> configuration very useful.
> 
> The feature (not the command line option, but the behaviour that is
> triggered by it) surely may be useful.  Otherwise we wouldn't have
> added it.  As I already said, I often find myself doing "--cached".
> But that does not make it a good idea to invent a new configuration
> variable and set "grep.source=cached".

I see.