Skip to content

Commit 5dd5007

Browse files
pks-tgitster
authored andcommitted
completion: adapt git-config(1) to complete subcommands
With fe3ccc7 (Merge branch 'ps/config-subcommands', 2024-05-15), git-config(1) has gained support for subcommands. These subcommands live next to the old, action-based mode, so that both the old and new way continue to work. The manpage for this command has been updated to prominently show the subcommands, and the action-based modes are marked as deprecated. Update Bash completion scripts accordingly to advertise subcommands instead of actions. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 19fe900 commit 5dd5007

File tree

2 files changed

+73
-25
lines changed

2 files changed

+73
-25
lines changed

contrib/completion/git-completion.bash

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2989,22 +2989,42 @@ __git_complete_config_variable_name_and_value ()
29892989

29902990
_git_config ()
29912991
{
2992-
case "$prev" in
2993-
--get|--get-all|--unset|--unset-all)
2994-
__gitcomp_nl "$(__git_config_get_set_variables)"
2992+
local subcommands subcommand
2993+
2994+
__git_resolve_builtins "config"
2995+
2996+
subcommands="$___git_resolved_builtins"
2997+
subcommand="$(__git_find_subcommand "$subcommands")"
2998+
2999+
if [ -z "$subcommand" ]
3000+
then
3001+
__gitcomp "$subcommands"
29953002
return
2996-
;;
2997-
*.*)
2998-
__git_complete_config_variable_value
3003+
fi
3004+
3005+
case "$cur" in
3006+
--*)
3007+
__gitcomp_builtin "config_$subcommand"
29993008
return
30003009
;;
30013010
esac
3002-
case "$cur" in
3003-
--*)
3004-
__gitcomp_builtin config
3011+
3012+
case "$subcommand" in
3013+
get)
3014+
__gitcomp_nl "$(__git_config_get_set_variables)"
30053015
;;
3006-
*)
3007-
__git_complete_config_variable_name
3016+
set)
3017+
case "$prev" in
3018+
*.*)
3019+
__git_complete_config_variable_value
3020+
;;
3021+
*)
3022+
__git_complete_config_variable_name
3023+
;;
3024+
esac
3025+
;;
3026+
unset)
3027+
__gitcomp_nl "$(__git_config_get_set_variables)"
30083028
;;
30093029
esac
30103030
}

t/t9902-completion.sh

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2742,30 +2742,58 @@ do
27422742
'
27432743
done
27442744

2745-
test_expect_success 'git config - section' '
2746-
test_completion "git config br" <<-\EOF
2745+
test_expect_success 'git config subcommand' '
2746+
test_completion "git config " <<-\EOF
2747+
edit Z
2748+
get Z
2749+
list Z
2750+
remove-section Z
2751+
rename-section Z
2752+
set Z
2753+
unset Z
2754+
EOF
2755+
'
2756+
2757+
test_expect_success 'git config subcommand options' '
2758+
test_completion "git config get --show-" <<-\EOF
2759+
--show-names Z
2760+
--show-origin Z
2761+
--show-scope Z
2762+
EOF
2763+
'
2764+
2765+
test_expect_success 'git config get' '
2766+
test_when_finished "rm -f cfgfile" &&
2767+
git config set --file cfgfile foo.bar baz &&
2768+
test_completion "git config get --file cfgfile foo." <<-\EOF
2769+
foo.bar Z
2770+
EOF
2771+
'
2772+
2773+
test_expect_success 'git config set - section' '
2774+
test_completion "git config set br" <<-\EOF
27472775
branch.Z
27482776
browser.Z
27492777
EOF
27502778
'
27512779

2752-
test_expect_success 'git config - section include, includeIf' '
2753-
test_completion "git config inclu" <<-\EOF
2780+
test_expect_success 'git config set - section include, includeIf' '
2781+
test_completion "git config set inclu" <<-\EOF
27542782
include.Z
27552783
includeIf.Z
27562784
EOF
27572785
'
27582786

2759-
test_expect_success 'git config - variable name' '
2760-
test_completion "git config log.d" <<-\EOF
2787+
test_expect_success 'git config set - variable name' '
2788+
test_completion "git config set log.d" <<-\EOF
27612789
log.date Z
27622790
log.decorate Z
27632791
log.diffMerges Z
27642792
EOF
27652793
'
27662794

2767-
test_expect_success 'git config - variable name include' '
2768-
test_completion "git config include.p" <<-\EOF
2795+
test_expect_success 'git config set - variable name include' '
2796+
test_completion "git config set include.p" <<-\EOF
27692797
include.path Z
27702798
EOF
27712799
'
@@ -2776,8 +2804,8 @@ test_expect_success 'setup for git config submodule tests' '
27762804
git submodule add ./sub
27772805
'
27782806

2779-
test_expect_success 'git config - variable name - submodule and __git_compute_first_level_config_vars_for_section' '
2780-
test_completion "git config submodule." <<-\EOF
2807+
test_expect_success 'git config set - variable name - submodule and __git_compute_first_level_config_vars_for_section' '
2808+
test_completion "git config set submodule." <<-\EOF
27812809
submodule.active Z
27822810
submodule.alternateErrorStrategy Z
27832811
submodule.alternateLocation Z
@@ -2788,8 +2816,8 @@ test_expect_success 'git config - variable name - submodule and __git_compute_fi
27882816
EOF
27892817
'
27902818

2791-
test_expect_success 'git config - variable name - __git_compute_second_level_config_vars_for_section' '
2792-
test_completion "git config submodule.sub." <<-\EOF
2819+
test_expect_success 'git config set - variable name - __git_compute_second_level_config_vars_for_section' '
2820+
test_completion "git config set submodule.sub." <<-\EOF
27932821
submodule.sub.url Z
27942822
submodule.sub.update Z
27952823
submodule.sub.branch Z
@@ -2799,8 +2827,8 @@ test_expect_success 'git config - variable name - __git_compute_second_level_con
27992827
EOF
28002828
'
28012829

2802-
test_expect_success 'git config - value' '
2803-
test_completion "git config color.pager " <<-\EOF
2830+
test_expect_success 'git config set - value' '
2831+
test_completion "git config set color.pager " <<-\EOF
28042832
false Z
28052833
true Z
28062834
EOF

0 commit comments

Comments
 (0)