completion: complete 'submodule.*' config variables

In the Bash completion script, function __git_complete_config_variable_name completes config variables and has special logic to deal with config variables involving user-defined names, like branch.<name>.* and remote.<name>.*. This special logic is missing for submodule-related config variables. Add the appropriate branches to the case statement, making use of the in-tree '.gitmodules' to list relevant submodules. Add corresponding tests in t9902-completion.sh, making sure we complete both first level submodule config variables as well as second level variables involving submodule names. Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Philippe Blain committed Feb 10, 2024 at 18:32 UTC b1d0cc68d1921f8d26a947fe662697e42dffb730
2 files changed +42
contrib/completion/git-completion.bash
+13
@@ -2803,6 +2803,19 @@ __git_complete_config_variable_name ()
2803 __gitcomp_nl_append "pushDefault" "$pfx" "$cur_" "${sfx:- }"
2804 return
2805 ;;
2806 + submodule.*.*)
2807 + local pfx="${cur_%.*}."
2808 + cur_="${cur_##*.}"
2809 + __gitcomp "url update branch fetchRecurseSubmodules ignore active" "$pfx" "$cur_" "$sfx"
2810 + return
2811 + ;;
2812 + submodule.*)
2813 + local pfx="${cur_%.*}."
2814 + cur_="${cur_#*.}"
2815 + __gitcomp_nl "$(__git config -f "$(__git rev-parse --show-toplevel)/.gitmodules" --get-regexp 'submodule.*.path' | awk -F. '{print $2}')" "$pfx" "$cur_" "."
2816 + __gitcomp_nl_append $'alternateErrorStrategy\nfetchJobs\nactive\nalternateLocation\nrecurse\npropagateBranches' "$pfx" "$cur_" "${sfx:- }"
2817 + return
2818 + ;;
2819 url.*.*)
2820 local pfx="${cur_%.*}."
2821 cur_="${cur_##*.}"
t/t9902-completion.sh
+29
@@ -2583,6 +2583,35 @@ test_expect_success 'git config - variable name include' '
2583 EOF
2584 '
2585
2586 +test_expect_success 'setup for git config submodule tests' '
2587 + test_create_repo sub &&
2588 + test_commit -C sub initial &&
2589 + git submodule add ./sub
2590 +'
2591 +
2592 +test_expect_success 'git config - variable name - submodule' '
2593 + test_completion "git config submodule." <<-\EOF
2594 + submodule.active Z
2595 + submodule.alternateErrorStrategy Z
2596 + submodule.alternateLocation Z
2597 + submodule.fetchJobs Z
2598 + submodule.propagateBranches Z
2599 + submodule.recurse Z
2600 + submodule.sub.Z
2601 + EOF
2602 +'
2603 +
2604 +test_expect_success 'git config - variable name - submodule names' '
2605 + test_completion "git config submodule.sub." <<-\EOF
2606 + submodule.sub.url Z
2607 + submodule.sub.update Z
2608 + submodule.sub.branch Z
2609 + submodule.sub.fetchRecurseSubmodules Z
2610 + submodule.sub.ignore Z
2611 + submodule.sub.active Z
2612 + EOF
2613 +'
2614 +
2615 test_expect_success 'git config - value' '
2616 test_completion "git config color.pager " <<-\EOF
2617 false Z