Thread (65 messages) 65 messages, 8 authors, 2022-04-06

Re: [PATCH 2/2] sparse-checkout: custom tab completion

From: Lessley Dennington <hidden>
Date: 2021-12-30 16:25:01

On 12/30/21 7:50 AM, Derrick Stolee wrote:
quoted
+__git_sparse_checkout_init_opts="--cone --sparse-index --no-sparse-index"
+
  _git_sparse_checkout ()
  {
-	local subcommands="list init set disable"
+	local subcommands="list init set disable add reapply"
  	local subcommand="$(__git_find_on_cmdline "$subcommands")"
+
  	if [ -z "$subcommand" ]; then
-		__gitcomp "$subcommands"
-		return
+		case "$cur" in
+			--*)
+				__gitcomp "--help"
+				;;
+			*)
+				__gitcomp "$subcommands"
+				;;
+		esac
This part fixes the --<tab> completion. I suppose if someone
did "-<tab>" then nothing would show up?
It actually shows a list of files that contain -- (if any exist).
quoted
  	fi
  
-	case "$subcommand,$cur" in
-	init,--*)
-		__gitcomp "--cone"
-		;;
-	set,--*)
-		__gitcomp "--stdin"
-		;;
-	*)
-		;;
+	case "$prev" in
+		init)
+			__gitcomp "$__git_sparse_checkout_init_opts"
+			;;
+		add|set)
+			__gitcomp "--stdin"
+			__gitcomp "$(git ls-tree -d -r HEAD --name-only)"> +			;;
With the thinking of rebasing onto en/sparse-checkout-set, this
could possibly be rearranged so the add|set) cases pass-through
into the init) and reapply) cases (skip the ;; between) to save
some duplication. Or, it is possible that doesn't work, but it
might be worth a try.
Thanks, I'll give this a go!
Also, since you are using 'git ls-tree' and not 'git ls-files',
the sparse index will not have an effect on the performance.
There will be some corner cases where a directory exists in one
of HEAD or the index but not the other. That's probably still
the right way to go since 'git ls-files' doesn't have a way to
only list directories. It just means that you probably don't
need to explicitly disable the sparse index in your test.
Will correct in v2.

-Lessley
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help