git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [RFH] "git -C there add foo" completes, s/add/diff/ does not
@ 2024-02-07 18:34 Junio C Hamano
  2024-02-08  2:50 ` Kyle Lippincott
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2024-02-07 18:34 UTC (permalink / raw
  To: git

As some of you may already know, I keep an untracked directory
called "Meta" at the top-level of the working tree of the Git
source tree.  This "Meta" directory is actually a single-branch
clone of the git.kernel.org/pub/scm/git/git.git that checks out
its "todo" branch, where files like whats-cooking.txt lives.

So, what I often would do is

    $ git -C Meta add whats-cooking.txt

after updating the draft of the next issue of the "What's cooking"
report.  The command line completion support for "git add" knows how
to complete this when I stopped typing the above after whats-" and
hit <TAB>.  It seems that __git_find_repo_path helper function that
notices "-C there" and discovers the $GIT_DIR, and _git_add helper
uses __git_complete_index_file that honors the discovered $GIT_DIR
to find paths in the correct index, which is wonderful.

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.

Anybody wants to take a crack at it?

Thanks.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFH] "git -C there add foo" completes, s/add/diff/ does not
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Kyle Lippincott @ 2024-02-08  2:50 UTC (permalink / raw
  To: Junio C Hamano; +Cc: git

On Wed, Feb 7, 2024 at 10:35 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> As some of you may already know, I keep an untracked directory
> called "Meta" at the top-level of the working tree of the Git
> source tree.  This "Meta" directory is actually a single-branch
> clone of the git.kernel.org/pub/scm/git/git.git that checks out
> its "todo" branch, where files like whats-cooking.txt lives.
>
> So, what I often would do is
>
>     $ git -C Meta add whats-cooking.txt
>
> after updating the draft of the next issue of the "What's cooking"
> report.  The command line completion support for "git add" knows how
> to complete this when I stopped typing the above after whats-" and
> hit <TAB>.  It seems that __git_find_repo_path helper function that
> notices "-C there" and discovers the $GIT_DIR, and _git_add helper
> uses __git_complete_index_file that honors the discovered $GIT_DIR
> to find paths in the correct index, which is wonderful.
>
> 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. For `git add`, it's checking the `git status` output to
filter the list to things that need to be added, so it respects the
`-C` option when calling into git to get that list, but there's no
such logic for `git diff` (the git-specific logic treats the
[optional] positional argument as a ref, not a file).

>
> Anybody wants to take a crack at it?
>
> Thanks.
>
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFH] "git -C there add foo" completes, s/add/diff/ does not
  2024-02-08  2:50 ` Kyle Lippincott
@ 2024-02-08  6:04   ` Junio C Hamano
  0 siblings, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2024-02-08  6:04 UTC (permalink / raw
  To: Kyle Lippincott; +Cc: git

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.



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-02-08  6:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).