Skip to content

Commit 09d04cb

Browse files
newrengitster
authored andcommitted
completion: avoid misleading completions in cone mode
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2eabbd6 commit 09d04cb

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

contrib/completion/git-completion.bash

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3090,6 +3090,26 @@ __gitcomp_directories ()
30903090
# No possible further completions any deeper, so assume we're at
30913091
# a leaf directory and just consider it complete
30923092
__gitcomp_direct_append "$cur "
3093+
elif [[ $_found == 0 ]]; then
3094+
# No possible completions found. Avoid falling back to
3095+
# bash's default file and directory completion, because all
3096+
# valid completions have already been searched and the
3097+
# fallbacks can do nothing but mislead. In fact, they can
3098+
# mislead in three different ways:
3099+
# 1) Fallback file completion makes no sense when asking
3100+
# for directory completions, as this function does.
3101+
# 2) Fallback directory completion is bad because
3102+
# e.g. "/pro" is invalid and should NOT complete to
3103+
# "/proc".
3104+
# 3) Fallback file/directory completion only completes
3105+
# on paths that exist in the current working tree,
3106+
# i.e. which are *already* part of their
3107+
# sparse-checkout. Thus, normal file and directory
3108+
# completion is always useless for "git
3109+
# sparse-checkout add" and is also probelmatic for
3110+
# "git sparse-checkout set" unless using it to
3111+
# strictly narrow the checkout.
3112+
COMPREPLY=( "" )
30933113
fi
30943114
}
30953115

0 commit comments

Comments
 (0)