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

Re: [PATCH] completion: zsh: support completion after "git -C <path>"

From
Lutz Lengemann <lutz@lengemann.net>
Date
Aug 17, 2026, 19:29 UTC
Message-ID
<a6a9fe7c-e46d-462f-b3b0-7ae6c2d52fe4@app.fastmail.com>
In-Reply-To
<CALnO6CB1vJ7RtBzTUSJSfYtfH+W2MZCFEkqNWeBXbWJ2r3Pdyg@mail.gmail.com>
Hi Ben
(Resending, my earlier reply was rejected by the list for being HTML.)
On Wed, Jul 15, 2026, at 00:34, D. Ben Knoble wrote:
> Any progress here? I just found my local copy of this patch and was
> briefly surprised to see it hadn't graduated anywhere (until I
> realized conversation had stalled at this point).

Sorry for the very late reply, I was on holiday and then other life things got in the way of answering :( I do have a v2 ready, which I have just pushed to my fork, and which follows this message.

Junio C Hamano <gitster@pobox.com> writes:
> Doesn't it want to do something similar to what __git_main in
> git-completion.bash does at the beginning, namely, this part?

It does, thanks. v2 no longer skips only leading -C options, but walks the words in front of the command and skips over the global options and, where they take one, their arguments, like __git_main does.

That also makes "git -p checkout <TAB>" and "git --git-dir=<path> checkout <TAB>" complete the arguments of the command, which they did not before.

Two related gaps are left alone, as they are bugs in the _arguments specification rather than in the command lookup: -c is not listed there at all, and --git-dir and friends are spelled "--git-dir=-", which accepts only "--git-dir=<path>", not the "--git-dir <path>" form. I can send patches for those separately.

"D. Ben Knoble" <ben.knoble@gmail.com> writes:
> But we mark these local, so how do they propagate to the other
> functions?

zsh scoping is dynamic, not lexical, so a variable declared "local" in __git_zsh_main is visible in the functions that are called from it, the bash helpers included. That is how __git_dir and __git_cmd_idx are handed down already, and __git_C_args works the same way.

> We should probably note in the log message that the _directories
> completion will not account for previous -C
I added a note about this in the log message.
> I think we could do _slightly_ better by using a state "->dir" or
> something, accumulating the current prefix, and passing that to
> _directories as a prefix with -W

I tried that and it works, but it changes what -C offers, which is more than fixing the completion after -C, so I left it out; happy to send it on top. Two things to watch out for there: the accumulated path has to be made absolute, as -W with ".." gave me the directories of "/", and the accumulation has to stop before the word that is being completed.

> By the way, I've realized that "git -<tab>" has the same problem (a
> giant list of files after the other option completions)

That one is older than this patch: the file listing comes from the fallback at the end of _git,

	let _ret && _default && _ret=0

which is where the "use-compctl" and "globbed-files" tags in your _complete_help dump come from. I could not reproduce the repeated description block with "zsh -f" and only the _complete completer, so something in my setup or yours may differ there. Either way it wants its own topic.

I hope that the change now looks good, and if there is anything I should still look at just tell me.

Thank you very much Lutz

Previous: D. Ben KnobleNext: D. Ben Knoble
Message 6 of 15 in “completion: zsh: support completion after "git -C <path>"”
  1. completion: zsh: support completion after "git -C <path>"Lutz Lengemann via GitGitGadget, Jun 17, 2026
  2. Ben KnobleJun 17, 2026
  3. Junio C HamanoJun 17, 2026
  4. D. Ben KnobleJun 18, 2026
  5. D. Ben KnobleJul 14, 2026
  6. Lutz LengemannAug 17, 2026
  7. D. Ben KnobleAug 18, 2026
  8. Lutz LengemannAug 18, 2026
  9. D. Ben KnobleAug 18, 2026
  10. completion: zsh: support completion after "git -C <path>"Lutz Lengemann via GitGitGadget, Aug 19, 2026
  11. D. Ben KnobleAug 20, 2026
  12. Junio C HamanoAug 20, 2026
  13. D. Ben KnobleAug 21, 2026
  14. Junio C HamanoAug 21, 2026
  15. Junio C HamanoAug 26, 2026

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.