Skip to content

Commit 6970252

Browse files
pcloudsgitster
authored andcommitted
completion: do not cache if --git-completion-helper fails
"git <cmd> --git-completion-helper" could fail if the command checks for a repo before parse_options(). If the result is cached, later on when the user moves to a worktree with repo, tab completion will still fail. Avoid this by detecting errors and not cache the completion output. We can try again and hopefully succeed next time (e.g. when a repo is found). Of course if --git-completion-helper fails permanently because of other reasons (*), this will slow down completion. But I don't see any better option to handle that case. (*) one of those cases is if __gitcomp_builtin is called on a command that does not support --git-completion-helper. And we do have a generic call __git_complete_common "$command" but this case is protected with __git_support_parseopt_helper so we're good. Reported-by: Felipe Contreras <[email protected]> Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aeb582a commit 6970252

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

contrib/completion/git-completion.bash

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,8 @@ __gitcomp_builtin ()
400400
if [ -z "$options" ]; then
401401
# leading and trailing spaces are significant to make
402402
# option removal work correctly.
403-
options=" $incl $(__git ${cmd/_/ } --git-completion-helper) "
403+
options=" $incl $(__git ${cmd/_/ } --git-completion-helper) " || return
404+
404405
for i in $excl; do
405406
options="${options/ $i / }"
406407
done

0 commit comments

Comments
 (0)