git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFH] "git -C there add foo" completes, s/add/diff/ does not

From
Kyle Lippincott <spectral@google.com>
Date
Feb 8, 2024, 02:50 UTC
Message-ID
<CAO_smVjnknv1ePTHhDNKK=C_iEg6+T0nNwaXqA67QuPd6tBkxw@mail.gmail.com>
In-Reply-To
<xmqqcyt89l7z.fsf@gitster.g>
On Wed, Feb 7, 2024 at 10:35 AM Junio C Hamano <gitster@pobox.com> wrote:
Show 25 quoted lines
>
> 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).

Show 6 quoted lines
>
> Anybody wants to take a crack at it?
>
> Thanks.
>
>
Previous: Junio C HamanoNext: Junio C Hamano
Message 2 of 3 in “[RFH] "git -C there add foo" completes, s/add/diff/ does not”
  1. Junio C HamanoFeb 7, 2024
  2. Kyle LippincottFeb 8, 2024
  3. Junio C HamanoFeb 8, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.