Skip to content

Commit

Permalink
completion: fix logic for determining whether cone mode is active
Browse files Browse the repository at this point in the history
_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 2d95707
("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 <[email protected]>
  • Loading branch information
newren committed Nov 23, 2023
1 parent 2546f26 commit 0be0e9c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions contrib/completion/git-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -3097,6 +3097,7 @@ _git_sparse_checkout ()
{
local subcommands="list init set disable add reapply"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
local using_cone=true
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
return
Expand All @@ -3107,8 +3108,15 @@ _git_sparse_checkout ()
__gitcomp_builtin sparse-checkout_$subcommand "" "--"
;;
set,*|add,*)
if [ "$(__git config core.sparseCheckoutCone)" == "true" ] ||
[ -n "$(__git_find_on_cmdline --cone)" ]; then
if [[ "$(__git config core.sparseCheckout)" == "true" &&
"$(__git config core.sparseCheckoutCone)" == "false" &&
-z "$(__git_find_on_cmdline --cone)" ]]; then
using_cone=false
fi
if [[ -n "$(__git_find_on_cmdline --no-cone)" ]]; then
using_cone=false
fi
if [[ "$using_cone" == "true" ]]; then
__gitcomp_directories
fi
esac
Expand Down

0 comments on commit 0be0e9c

Please sign in to comment.