public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox•com>
To: Kyle Lippincott <spectral@google•com>
Cc: git@vger•kernel.org
Subject: Re: [RFH] "git -C there add foo" completes, s/add/diff/ does not
Date: Wed, 07 Feb 2024 22:04:40 -0800	[thread overview]
Message-ID: <xmqqmssbpk3r.fsf@gitster.g> (raw)
In-Reply-To: <CAO_smVjnknv1ePTHhDNKK=C_iEg6+T0nNwaXqA67QuPd6tBkxw@mail.gmail.com> (Kyle Lippincott's message of "Wed, 7 Feb 2024 18:50:02 -0800")

Kyle Lippincott <spectral@google•com> writes:

>> ...
>> But the same does not work for the step before I can decide to
>> actually "add" the contents, which is to "diff", i.e.
>>
>>     $ git -C Meta diff whats-<TAB>
>>
>> does not complete.
>
> I'm not a completions expert, but I think what's happening is that the
> completions for `git diff` aren't producing anything, so it (where
> "it" here might be the shell?) falls back to just doing normal path
> completion.

Yes, that seems to be the case.

> For `git add`, it's checking the `git status` output to
> filter the list to things that need to be added,...

Not exactly, but a close enough description, I think.

__git_complete_index_file does not run `git status` but asks
ls-files the paths it knows about (including "--others" so that a
path that is untracked can become a candidate to be added), then
massages the list of paths with a custom awk script.

For "git diff", depending on what two sets of contents are being
compared, the source of possible paths may differ, but the list of
paths obtained from ls-files (without --others) would be appropriate
when comparing the index and the working tree files, or comparing a
tree-ish and the working tree files.  The necessary ingredient to do
so may be pretty much the same as what is used by _git_add completion.

When comparing two tree-ishes, the candidate would ideally come from
union of paths in these two tree-ishes, but I offhand do not know if
there already is a support for choosing from such a set.

Thanks.


      reply	other threads:[~2024-02-08  6:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-07 18:34 [RFH] "git -C there add foo" completes, s/add/diff/ does not Junio C Hamano
2024-02-08  2:50 ` Kyle Lippincott
2024-02-08  6:04   ` Junio C Hamano [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqmssbpk3r.fsf@gitster.g \
    --to=gitster@pobox$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=spectral@google$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox