From: Junio C Hamano Date: Wed, 17 Jun 2026 17:21:50 GMT Subject: Re: [PATCH] completion: zsh: support completion after "git -C " Message-ID: In-Reply-To: "Lutz Lengemann via GitGitGadget" writes: > From: Lutz Lengemann > > The zsh completion wrapper (__git_zsh_main) did not handle the global -C > option, so "git -C " 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 ]: :_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" 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" 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