From: Junio C Hamano <gitster@pobox.com>
To: "Lutz Lengemann via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Lutz Lengemann <lutz@lengemann.net>
Subject: Re: [PATCH] completion: zsh: support completion after "git -C <path>"
Date: Wed, 17 Jun 2026 10:21:50 -0700 [thread overview]
Message-ID: <xmqqa4stw09d.fsf@gitster.g> (raw)
In-Reply-To: <pull.2155.git.1781710256081.gitgitgadget@gmail.com> (Lutz Lengemann via GitGitGadget's message of "Wed, 17 Jun 2026 15:30:55 +0000")
"Lutz Lengemann via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Lutz Lengemann <lutz@lengemann.net>
>
> The zsh completion wrapper (__git_zsh_main) did not handle the global -C
> option, so "git -C <path> <command> <TAB>" offered nothing and could not
> complete a command's arguments.
I do not write, use, or customize zsh, so please take my comments
with huge grains of salt, or just ignore them completely (your
choice) ;-), but one thng I noticed was that ...
> diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
> index c32186a977..323049be8b 100644
> --- a/contrib/completion/git-completion.zsh
> +++ b/contrib/completion/git-completion.zsh
> @@ -227,6 +227,7 @@ __git_zsh_main ()
> '(-p --paginate --no-pager)'{-p,--paginate}'[pipe all output into ''less'']' \
> '(-p --paginate)--no-pager[do not pipe git output into a pager]' \
> '--git-dir=-[set the path to the repository]: :_directories' \
> + '*-C[run as if git was started in <path>]: :_directories' \
> '--bare[treat the repository as a bare repository]' \
> '(- :)--version[prints the git suite version]' \
> '--exec-path=-[path to where your core git programs are installed]:: :_directories' \
... this part talks about not just "-C<dir>" but knows about
all the other options that the "git" potty itself takes, while ...
> @@ -252,6 +253,14 @@ __git_zsh_main ()
> ;;
> (arg)
> local command="${words[1]}" __git_dir __git_cmd_idx=1
> + local -a __git_C_args
> + local -i i=2
> +
> + while [[ ${orig_words[i]} == -C ]]; do
> + __git_C_args+=(-C ${orig_words[i+1]})
> + (( __git_cmd_idx += 2 ))
> + (( i += 2 ))
> + done
... this only knows about "-C<dir>" and nothing else.
Doesn't it want to do something similar to what __git_main in
git-completion.bash does at the beginning, namely, this part?
__git_main ()
{
local i c=1 command __git_dir __git_repo_path
local __git_C_args C_args_count=0
local __git_cmd_idx
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
--git-dir=*)
__git_dir="${i#--git-dir=}"
;;
--git-dir)
((c++))
__git_dir="${words[c]}"
;;
--bare)
__git_dir="."
;;
--help)
command="help"
break
;;
-c|--work-tree|--namespace)
((c++))
;;
-C)
__git_C_args[C_args_count++]=-C
((c++))
__git_C_args[C_args_count++]="${words[c]}"
;;
-*)
;;
*)
command="$i"
__git_cmd_idx="$c"
break
;;
esac
((c++))
done
prev parent reply other threads:[~2026-06-17 17:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-17 15:30 [PATCH] completion: zsh: support completion after "git -C <path>" Lutz Lengemann via GitGitGadget
2026-06-17 17:17 ` Ben Knoble
2026-06-17 17:21 ` 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=xmqqa4stw09d.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=lutz@lengemann.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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