All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: "Elijah Newren" <newren@gmail.com>,
	"SZEDER Gábor" <szeder.dev@gmail.com>,
	"Elijah Newren" <newren@gmail.com>,
	"Elijah Newren" <newren@gmail.com>
Subject: [PATCH v3 2/4] completion: fix logic for determining whether cone mode is active
Date: Sun, 03 Dec 2023 05:57:02 +0000	[thread overview]
Message-ID: <212ba35ed469b63fc75c51b61588025c303a162d.1701583024.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1349.v3.git.1701583024.gitgitgadget@gmail.com>

From: Elijah Newren <newren@gmail.com>

_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>
---
 contrib/completion/git-completion.bash | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index b8661701718..7aa66c19ede 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -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
@@ -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
-- 
gitgitgadget


  parent reply	other threads:[~2023-12-03  5:57 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-23 17:44 [PATCH 0/4] Sparse checkout completion fixes Elijah Newren via GitGitGadget
2023-11-23 17:44 ` [PATCH 1/4] completion: squelch stray errors in sparse-checkout completion Elijah Newren via GitGitGadget
2023-11-24 18:39   ` SZEDER Gábor
2023-11-24 20:05     ` Elijah Newren
2023-11-23 17:44 ` [PATCH 2/4] completion: fix logic for determining whether cone mode is active Elijah Newren via GitGitGadget
2023-11-23 17:44 ` [PATCH 3/4] completion: avoid misleading completions in cone mode Elijah Newren via GitGitGadget
2023-11-23 17:44 ` [PATCH 4/4] completion: avoid user confusion in non-cone mode Elijah Newren via GitGitGadget
2023-11-24  1:19   ` Junio C Hamano
2023-11-24 15:28     ` Elijah Newren
2023-11-27  1:39       ` Junio C Hamano
2023-12-03  5:57         ` Elijah Newren
2023-11-26  7:51 ` [PATCH v2 0/4] Sparse checkout completion fixes Elijah Newren via GitGitGadget
2023-11-26  7:51   ` [PATCH v2 1/4] completion: squelch stray errors in sparse-checkout completion Elijah Newren via GitGitGadget
2023-11-26  7:51   ` [PATCH v2 2/4] completion: fix logic for determining whether cone mode is active Elijah Newren via GitGitGadget
2023-11-26  7:51   ` [PATCH v2 3/4] completion: avoid misleading completions in cone mode Elijah Newren via GitGitGadget
2023-11-26  7:51   ` [PATCH v2 4/4] completion: avoid user confusion in non-cone mode Elijah Newren via GitGitGadget
2023-12-03  5:57   ` [PATCH v3 0/4] Sparse checkout completion fixes Elijah Newren via GitGitGadget
2023-12-03  5:57     ` [PATCH v3 1/4] completion: squelch stray errors in sparse-checkout completion Elijah Newren via GitGitGadget
2023-12-03  5:57     ` Elijah Newren via GitGitGadget [this message]
2023-12-03  5:57     ` [PATCH v3 3/4] completion: avoid misleading completions in cone mode Elijah Newren via GitGitGadget
2023-12-03  5:57     ` [PATCH v3 4/4] completion: avoid user confusion in non-cone mode Elijah Newren via GitGitGadget
2023-12-03 13:15       ` Junio C Hamano

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=212ba35ed469b63fc75c51b61588025c303a162d.1701583024.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=newren@gmail.com \
    --cc=szeder.dev@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.