]> git.ipfire.org Git - thirdparty/git.git/commitdiff
completion: adapt git-config(1) to complete subcommands
authorPatrick Steinhardt <ps@pks.im>
Fri, 17 May 2024 06:13:36 +0000 (08:13 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 17 May 2024 16:26:19 +0000 (09:26 -0700)
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>
contrib/completion/git-completion.bash
t/t9902-completion.sh

index 5c0ddeb3d4fb60fc6b8e5d08b4b0e779544ff15d..60a22d619a85cc17334ef2e73185048120d3e51f 100644 (file)
@@ -2989,22 +2989,42 @@ __git_complete_config_variable_name_and_value ()
 
 _git_config ()
 {
-       case "$prev" in
-       --get|--get-all|--unset|--unset-all)
-               __gitcomp_nl "$(__git_config_get_set_variables)"
+       local subcommands subcommand
+
+       __git_resolve_builtins "config"
+
+       subcommands="$___git_resolved_builtins"
+       subcommand="$(__git_find_subcommand "$subcommands")"
+
+       if [ -z "$subcommand" ]
+       then
+               __gitcomp "$subcommands"
                return
-               ;;
-       *.*)
-               __git_complete_config_variable_value
+       fi
+
+       case "$cur" in
+       --*)
+               __gitcomp_builtin "config_$subcommand"
                return
                ;;
        esac
-       case "$cur" in
-       --*)
-               __gitcomp_builtin config
+
+       case "$subcommand" in
+       get)
+               __gitcomp_nl "$(__git_config_get_set_variables)"
                ;;
-       *)
-               __git_complete_config_variable_name
+       set)
+               case "$prev" in
+               *.*)
+                       __git_complete_config_variable_value
+                       ;;
+               *)
+                       __git_complete_config_variable_name
+                       ;;
+               esac
+               ;;
+       unset)
+               __gitcomp_nl "$(__git_config_get_set_variables)"
                ;;
        esac
 }
index 963f865f27ed0589600d780745ff09865a2f9c7e..64c99794238406b07a84ec06297cdc3c393d4377 100755 (executable)
@@ -2742,30 +2742,58 @@ do
        '
 done
 
-test_expect_success 'git config - section' '
-       test_completion "git config br" <<-\EOF
+test_expect_success 'git config subcommand' '
+       test_completion "git config " <<-\EOF
+       edit Z
+       get Z
+       list Z
+       remove-section Z
+       rename-section Z
+       set Z
+       unset Z
+       EOF
+'
+
+test_expect_success 'git config subcommand options' '
+       test_completion "git config get --show-" <<-\EOF
+       --show-names Z
+       --show-origin Z
+       --show-scope Z
+       EOF
+'
+
+test_expect_success 'git config get' '
+       test_when_finished "rm -f cfgfile" &&
+       git config set --file cfgfile foo.bar baz &&
+       test_completion "git config get --file cfgfile foo." <<-\EOF
+       foo.bar Z
+       EOF
+'
+
+test_expect_success 'git config set - section' '
+       test_completion "git config set br" <<-\EOF
        branch.Z
        browser.Z
        EOF
 '
 
-test_expect_success 'git config - section include, includeIf' '
-       test_completion "git config inclu" <<-\EOF
+test_expect_success 'git config set - section include, includeIf' '
+       test_completion "git config set inclu" <<-\EOF
        include.Z
        includeIf.Z
        EOF
 '
 
-test_expect_success 'git config - variable name' '
-       test_completion "git config log.d" <<-\EOF
+test_expect_success 'git config set - variable name' '
+       test_completion "git config set log.d" <<-\EOF
        log.date Z
        log.decorate Z
        log.diffMerges Z
        EOF
 '
 
-test_expect_success 'git config - variable name include' '
-       test_completion "git config include.p" <<-\EOF
+test_expect_success 'git config set - variable name include' '
+       test_completion "git config set include.p" <<-\EOF
        include.path Z
        EOF
 '
@@ -2776,8 +2804,8 @@ test_expect_success 'setup for git config submodule tests' '
        git submodule add ./sub
 '
 
-test_expect_success 'git config - variable name - submodule and __git_compute_first_level_config_vars_for_section' '
-       test_completion "git config submodule." <<-\EOF
+test_expect_success 'git config set - variable name - submodule and __git_compute_first_level_config_vars_for_section' '
+       test_completion "git config set submodule." <<-\EOF
        submodule.active Z
        submodule.alternateErrorStrategy Z
        submodule.alternateLocation Z
@@ -2788,8 +2816,8 @@ test_expect_success 'git config - variable name - submodule and __git_compute_fi
        EOF
 '
 
-test_expect_success 'git config - variable name - __git_compute_second_level_config_vars_for_section' '
-       test_completion "git config submodule.sub." <<-\EOF
+test_expect_success 'git config set - variable name - __git_compute_second_level_config_vars_for_section' '
+       test_completion "git config set submodule.sub." <<-\EOF
        submodule.sub.url Z
        submodule.sub.update Z
        submodule.sub.branch Z
@@ -2799,8 +2827,8 @@ test_expect_success 'git config - variable name - __git_compute_second_level_con
        EOF
 '
 
-test_expect_success 'git config - value' '
-       test_completion "git config color.pager " <<-\EOF
+test_expect_success 'git config set - value' '
+       test_completion "git config set color.pager " <<-\EOF
        false Z
        true Z
        EOF