Skip to content

Commit b1d0cc6

Browse files
phil-blaingitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 30bd55f commit b1d0cc6

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

contrib/completion/git-completion.bash

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2803,6 +2803,19 @@ __git_complete_config_variable_name ()
28032803
__gitcomp_nl_append "pushDefault" "$pfx" "$cur_" "${sfx:- }"
28042804
return
28052805
;;
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+
;;
28062819
url.*.*)
28072820
local pfx="${cur_%.*}."
28082821
cur_="${cur_##*.}"

t/t9902-completion.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,6 +2583,35 @@ test_expect_success 'git config - variable name include' '
25832583
EOF
25842584
'
25852585

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+
25862615
test_expect_success 'git config - value' '
25872616
test_completion "git config color.pager " <<-\EOF
25882617
false Z

0 commit comments

Comments
 (0)