Skip to content

Commit d9f88dd

Browse files
avargitster
authored andcommitted
completion: add a GIT_COMPLETION_SHOW_ALL_COMMANDS
Add a GIT_COMPLETION_SHOW_ALL_COMMANDS=1 configuration setting to go with the existing GIT_COMPLETION_SHOW_ALL=1 added in c099f57 (completion: add GIT_COMPLETION_SHOW_ALL env var, 2020-08-19). This will include plumbing commands such as "cat-file" in "git <TAB>" and "git c<TAB>" completion. Without/with this I have 134 and 243 completion with git <TAB>, respectively. It was already possible to do this by tweaking GIT_TESTING_PORCELAIN_COMMAND_LIST= from the outside, that testing variable was added in 84a9713 (completion: let git provide the completable command list, 2018-05-20). Doing this before loading git-completion.bash worked: export GIT_TESTING_PORCELAIN_COMMAND_LIST="$(git --list-cmds=builtins,main,list-mainporcelain,others,nohelpers,alias,list-complete,config)" But such testing variables are not meant to be used from the outside, and we make no guarantees that those internal won't change. So let's expose this as a dedicated configuration knob. It would be better to teach --list-cmds=* a new category which would include all of these groups, but that's a larger change that we can leave for some other time. 1. https://lore.kernel.org/git/CAGP6POJ9gwp+t-eP3TPkivBLLbNb2+qj=61Mehcj=1BgrVOSLA@mail.gmail.com/ Reported-by: Hongyi Zhao <[email protected]> Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 59d9442 commit d9f88dd

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

contrib/completion/git-completion.bash

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@
4949
# and git-switch completion (e.g., completing "foo" when "origin/foo"
5050
# exists).
5151
#
52+
# GIT_COMPLETION_SHOW_ALL_COMMANDS
53+
#
54+
# When set to "1" suggest all commands, including plumbing commands
55+
# which are hidden by default (e.g. "cat-file" on "git ca<TAB>").
56+
#
5257
# GIT_COMPLETION_SHOW_ALL
5358
#
5459
# When set to "1" suggest all options, including options which are
@@ -3455,7 +3460,13 @@ __git_main ()
34553460
then
34563461
__gitcomp "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
34573462
else
3458-
__gitcomp "$(__git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config)"
3463+
local list_cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config
3464+
3465+
if test "${GIT_COMPLETION_SHOW_ALL_COMMANDS-}" = "1"
3466+
then
3467+
list_cmds=builtins,$list_cmds
3468+
fi
3469+
__gitcomp "$(__git --list-cmds=$list_cmds)"
34593470
fi
34603471
;;
34613472
esac

t/t9902-completion.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2440,6 +2440,37 @@ test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '
24402440
)
24412441
'
24422442

2443+
test_expect_success 'plumbing commands are excluded without GIT_COMPLETION_SHOW_ALL_COMMANDS' '
2444+
(
2445+
. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2446+
sane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&
2447+
2448+
# Just mainporcelain, not plumbing commands
2449+
run_completion "git c" &&
2450+
grep checkout out &&
2451+
! grep cat-file out
2452+
)
2453+
'
2454+
2455+
test_expect_success 'all commands are shown with GIT_COMPLETION_SHOW_ALL_COMMANDS (also main non-builtin)' '
2456+
(
2457+
. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2458+
GIT_COMPLETION_SHOW_ALL_COMMANDS=1 &&
2459+
export GIT_COMPLETION_SHOW_ALL_COMMANDS &&
2460+
sane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&
2461+
2462+
# Both mainporcelain and plumbing commands
2463+
run_completion "git c" &&
2464+
grep checkout out &&
2465+
grep cat-file out &&
2466+
2467+
# Check "gitk", a "main" command, but not a built-in + more plumbing
2468+
run_completion "git g" &&
2469+
grep gitk out &&
2470+
grep get-tar-commit-id out
2471+
)
2472+
'
2473+
24432474
test_expect_success '__git_complete' '
24442475
unset -f __git_wrap__git_main &&
24452476

0 commit comments

Comments
 (0)