Re: [PATCH] completion: complete tracked paths for 'git diff'

Junio C Hamano <[email protected]> Mon, 03 Aug 2026 08:45:39 -0700
Newsgroups org.kernel.vger.git
Message-ID <[email protected]>
Junio C Hamano <[email protected]> writes:

> SZEDER Gábor <[email protected]> writes:
>
>> I think we should check whether the '--no-index' option is present on
>> the command line, and simply not call __git_complete_index_file() if
>> it is, to let Bash list all paths; i.e. each of those calls should be
>> protected by an additional 'if test -z "$(__git_find_on_cmdline
>> "--no-index")' condition, perhaps.
>
>
> Ah, I did not think of the "we made 'git diff' work without Git"
> mode at all.
>
> But I would avoid scanning the command line for '--no-index' for two
> reasons:
>
>  (1) "git diff -S --no-index maint master" would not give you the
>      '--no-index' mode.
>
>  (2) When run outside the working tree of a repository, you do not
>      have to say '--no-index'.
>
> These make detecting the "'git diff' but not Git" mode tedious and
> error-prone.
>
> I have not tried this, but if we arranged the code to fall back
> further to Bash-native "paths in $PWD" after the completion code in
> the posted patch found nothing, would it be sufficient?

Eh, isn't the code already arranged to do so?  With the posted
completion script loaded, I do

	$ cd $HOME
	$ git diff [--no-index] w/git.git/C<TAB>

where (1) my $HOME is not under version control (dotfiles are
installed after getting built from their sources that are version
controlled elsewhere), and (2) ~/w/git.git/ is the primary working
tree I work in.  I see

	Cargo.toml  CODE_OF_CONDUCT.md  COPYING

offered as choices.  As there is no index or rev when I am in my
$HOME directory, naturally the only completion that kicks in is the
bash native "paths we see".

So I think I do not need anything special to "arrange" the fallback.

Thanks.