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 v2 3/4] completion: avoid misleading completions in cone mode
Date: Sun, 26 Nov 2023 07:51:25 +0000	[thread overview]
Message-ID: <1cbbcd9097c96b7646fb0c756c3964413f2a021f.1700985086.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1349.v2.git.1700985086.gitgitgadget@gmail.com>

From: Elijah Newren <newren@gmail.com>

The "set" and "add" subcommands of "sparse-checkout", when in cone mode,
should only complete on directories.  For bash_completion in general,
when no completions are returned for any subcommands, it will often fall
back to standard completion of files and directories as a substitute.
That is not helpful here.  Since we have already looked for all valid
completions, if none are found then falling back to standard bash file
and directory completion is at best actively misleading.  In fact, there
are three different ways it can be actively misleading.  Add a long
comment in the code about how that fallback behavior can deceive, and
disable the fallback by returning a fake result as the sole completion.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 contrib/completion/git-completion.bash | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 7aa66c19ede..c614e5d4f07 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -3090,6 +3090,26 @@ __gitcomp_directories ()
 		# No possible further completions any deeper, so assume we're at
 		# a leaf directory and just consider it complete
 		__gitcomp_direct_append "$cur "
+	elif [[ $_found == 0 ]]; then
+		# No possible completions found.  Avoid falling back to
+		# bash's default file and directory completion, because all
+		# valid completions have already been searched and the
+		# fallbacks can do nothing but mislead.  In fact, they can
+		# mislead in three different ways:
+		#    1) Fallback file completion makes no sense when asking
+		#       for directory completions, as this function does.
+		#    2) Fallback directory completion is bad because
+		#       e.g. "/pro" is invalid and should NOT complete to
+		#       "/proc".
+		#    3) Fallback file/directory completion only completes
+		#       on paths that exist in the current working tree,
+		#       i.e. which are *already* part of their
+		#       sparse-checkout.  Thus, normal file and directory
+		#       completion is always useless for "git
+		#       sparse-checkout add" and is also probelmatic for
+		#       "git sparse-checkout set" unless using it to
+		#       strictly narrow the checkout.
+		COMPREPLY=( "" )
 	fi
 }
 
-- 
gitgitgadget


  parent reply	other threads:[~2023-11-26  7:51 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   ` Elijah Newren via GitGitGadget [this message]
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     ` [PATCH v3 2/4] completion: fix logic for determining whether cone mode is active Elijah Newren via GitGitGadget
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=1cbbcd9097c96b7646fb0c756c3964413f2a021f.1700985086.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.