completion: fix logic for determining whether cone mode is active

_git_sparse_checkout() was checking whether we were in cone mode by checking whether either: A) core.sparseCheckoutCone was "true" B) "--cone" was specified on the command line This code has 2 bugs I didn't catch in my review at the time 1) core.sparseCheckout must be "true" for core.sparseCheckoutCone to be relevant (which matters since "git sparse-checkout disable" only unsets core.sparseCheckout, not core.sparseCheckoutCone) 2) The presence of "--no-cone" should override any config setting Further, I forgot to update this logic as part of 2d95707a02 ("sparse-checkout: make --cone the default", 2022-04-22) for the new default. Update the code for the new default and make it be more careful in determining whether to complete based on cone mode or non-cone mode. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Dec 3, 2023 at 05:57 UTC 253eeaf7a2bc93285b55e2be8aa15f27cd11858e
1 file changed +10 -2
contrib/completion/git-completion.bash
+10 -2
@@ -3097,6 +3097,7 @@ _git_sparse_checkout ()
3097 {
3098 local subcommands="list init set disable add reapply"
3099 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3100 + local using_cone=true
3101 if [ -z "$subcommand" ]; then
3102 __gitcomp "$subcommands"
3103 return
@@ -3107,8 +3108,15 @@ _git_sparse_checkout ()
3108 __gitcomp_builtin sparse-checkout_$subcommand "" "--"
3109 ;;
3110 set,*|add,*)
3110 - if [ "$(__git config core.sparseCheckoutCone)" == "true" ] ||
3111 - [ -n "$(__git_find_on_cmdline --cone)" ]; then
3111 + if [[ "$(__git config core.sparseCheckout)" == "true" &&
3112 + "$(__git config core.sparseCheckoutCone)" == "false" &&
3113 + -z "$(__git_find_on_cmdline --cone)" ]]; then
3114 + using_cone=false
3115 + fi
3116 + if [[ -n "$(__git_find_on_cmdline --no-cone)" ]]; then
3117 + using_cone=false
3118 + fi
3119 + if [[ "$using_cone" == "true" ]]; then
3120 __gitcomp_directories
3121 fi
3122 esac