git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 2/4] completion: fix logic for determining whether cone mode is active

From
Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>
Date
Dec 3, 2023, 05:57 UTC
Message-ID
<212ba35ed469b63fc75c51b61588025c303a162d.1701583024.git.gitgitgadget@gmail.com>
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
Previous: Elijah Newren via GitGitGadgetNext: Elijah Newren via GitGitGadget
Message 19 of 22 in “Sparse checkout completion fixes”
  1. 0/4 Sparse checkout completion fixesElijah Newren via GitGitGadget, Nov 23, 2023
  2. 1/4 completion: squelch stray errors in sparse-checkout completionElijah Newren via GitGitGadget, Nov 23, 2023
  3. SZEDER GáborNov 24, 2023
  4. Elijah NewrenNov 24, 2023
  5. 2/4 completion: fix logic for determining whether cone mode is activeElijah Newren via GitGitGadget, Nov 23, 2023
  6. 3/4 completion: avoid misleading completions in cone modeElijah Newren via GitGitGadget, Nov 23, 2023
  7. 4/4 completion: avoid user confusion in non-cone modeElijah Newren via GitGitGadget, Nov 23, 2023
  8. Junio C HamanoNov 24, 2023
  9. Elijah NewrenNov 24, 2023
  10. Junio C HamanoNov 27, 2023
  11. Elijah NewrenDec 3, 2023
  12. 0/4 Sparse checkout completion fixesElijah Newren via GitGitGadget, Nov 26, 2023
  13. 1/4 completion: squelch stray errors in sparse-checkout completionElijah Newren via GitGitGadget, Nov 26, 2023
  14. 2/4 completion: fix logic for determining whether cone mode is activeElijah Newren via GitGitGadget, Nov 26, 2023
  15. 3/4 completion: avoid misleading completions in cone modeElijah Newren via GitGitGadget, Nov 26, 2023
  16. 4/4 completion: avoid user confusion in non-cone modeElijah Newren via GitGitGadget, Nov 26, 2023
  17. 0/4 Sparse checkout completion fixesElijah Newren via GitGitGadget, Dec 3, 2023
  18. 1/4 completion: squelch stray errors in sparse-checkout completionElijah Newren via GitGitGadget, Dec 3, 2023
  19. 2/4 completion: fix logic for determining whether cone mode is activeElijah Newren via GitGitGadget, Dec 3, 2023
  20. 3/4 completion: avoid misleading completions in cone modeElijah Newren via GitGitGadget, Dec 3, 2023
  21. 4/4 completion: avoid user confusion in non-cone modeElijah Newren via GitGitGadget, Dec 3, 2023
  22. Junio C HamanoDec 3, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.