completion: adapt git-config(1) to complete subcommands

With fe3ccc7aab (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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed May 17, 2024 at 08:13 UTC 5dd5007f8936f8d37cf95119e83039bd9237a3c5
2 files changed +73 -25
contrib/completion/git-completion.bash
+31 -11
@@ -2989,22 +2989,42 @@ __git_complete_config_variable_name_and_value ()
2989
2990 _git_config ()
2991 {
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"
3002 return
2996 - ;;
2997 - *.*)
2998 - __git_complete_config_variable_value
3003 + fi
3004 +
3005 + case "$cur" in
3006 + --*)
3007 + __gitcomp_builtin "config_$subcommand"
3008 return
3009 ;;
3010 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)"
3015 ;;
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)"
3028 ;;
3029 esac
3030 }
t/t9902-completion.sh
+42 -14
@@ -2742,30 +2742,58 @@ do
2742 '
2743 done
2744
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
2775 branch.Z
2776 browser.Z
2777 EOF
2778 '
2779
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
2782 include.Z
2783 includeIf.Z
2784 EOF
2785 '
2786
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
2789 log.date Z
2790 log.decorate Z
2791 log.diffMerges Z
2792 EOF
2793 '
2794
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
2797 include.path Z
2798 EOF
2799 '
@@ -2776,8 +2804,8 @@ test_expect_success 'setup for git config submodule tests' '
2804 git submodule add ./sub
2805 '
2806
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
2809 submodule.active Z
2810 submodule.alternateErrorStrategy Z
2811 submodule.alternateLocation Z
@@ -2788,8 +2816,8 @@ test_expect_success 'git config - variable name - submodule and __git_compute_fi
2816 EOF
2817 '
2818
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
2821 submodule.sub.url Z
2822 submodule.sub.update Z
2823 submodule.sub.branch Z
@@ -2799,8 +2827,8 @@ test_expect_success 'git config - variable name - __git_compute_second_level_con
2827 EOF
2828 '
2829
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
2832 false Z
2833 true Z
2834 EOF