Skip to content

Commit 89400c3

Browse files
committed
Merge branch 'pb/complete-config'
The command line completion script (in contrib/) learned to complete configuration variable names better. * pb/complete-config: completion: add and use __git_compute_second_level_config_vars_for_section completion: add and use __git_compute_first_level_config_vars_for_section completion: complete 'submodule.*' config variables completion: add space after config variable names also in Bash 3
2 parents c59ba68 + 6e32f71 commit 89400c3

File tree

2 files changed

+75
-44
lines changed

2 files changed

+75
-44
lines changed

contrib/completion/git-completion.bash

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2660,6 +2660,31 @@ __git_compute_config_vars ()
26602660
__git_config_vars="$(git help --config-for-completion)"
26612661
}
26622662

2663+
__git_config_vars_all=
2664+
__git_compute_config_vars_all ()
2665+
{
2666+
test -n "$__git_config_vars_all" ||
2667+
__git_config_vars_all="$(git --no-pager help --config)"
2668+
}
2669+
2670+
__git_compute_first_level_config_vars_for_section ()
2671+
{
2672+
local section="$1"
2673+
__git_compute_config_vars
2674+
local this_section="__git_first_level_config_vars_for_section_${section}"
2675+
test -n "${!this_section}" ||
2676+
printf -v "__git_first_level_config_vars_for_section_${section}" %s "$(echo "$__git_config_vars" | grep -E "^${section}\.[a-z]" | awk -F. '{print $2}')"
2677+
}
2678+
2679+
__git_compute_second_level_config_vars_for_section ()
2680+
{
2681+
local section="$1"
2682+
__git_compute_config_vars_all
2683+
local this_section="__git_second_level_config_vars_for_section_${section}"
2684+
test -n "${!this_section}" ||
2685+
printf -v "__git_second_level_config_vars_for_section_${section}" %s "$(echo "$__git_config_vars_all" | grep -E "^${section}\.<" | awk -F. '{print $3}')"
2686+
}
2687+
26632688
__git_config_sections=
26642689
__git_compute_config_sections ()
26652690
{
@@ -2804,73 +2829,50 @@ __git_complete_config_variable_name ()
28042829
done
28052830

28062831
case "$cur_" in
2807-
branch.*.*)
2832+
branch.*.*|guitool.*.*|difftool.*.*|man.*.*|mergetool.*.*|remote.*.*|submodule.*.*|url.*.*)
28082833
local pfx="${cur_%.*}."
28092834
cur_="${cur_##*.}"
2810-
__gitcomp "remote pushRemote merge mergeOptions rebase" "$pfx" "$cur_" "$sfx"
2835+
local section="${pfx%.*.}"
2836+
__git_compute_second_level_config_vars_for_section "${section}"
2837+
local this_section="__git_second_level_config_vars_for_section_${section}"
2838+
__gitcomp "${!this_section}" "$pfx" "$cur_" "$sfx"
28112839
return
28122840
;;
28132841
branch.*)
28142842
local pfx="${cur_%.*}."
28152843
cur_="${cur_#*.}"
2844+
local section="${pfx%.}"
28162845
__gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
2817-
__gitcomp_nl_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "${sfx- }"
2818-
return
2819-
;;
2820-
guitool.*.*)
2821-
local pfx="${cur_%.*}."
2822-
cur_="${cur_##*.}"
2823-
__gitcomp "
2824-
argPrompt cmd confirm needsFile noConsole noRescan
2825-
prompt revPrompt revUnmerged title
2826-
" "$pfx" "$cur_" "$sfx"
2827-
return
2828-
;;
2829-
difftool.*.*)
2830-
local pfx="${cur_%.*}."
2831-
cur_="${cur_##*.}"
2832-
__gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
2833-
return
2834-
;;
2835-
man.*.*)
2836-
local pfx="${cur_%.*}."
2837-
cur_="${cur_##*.}"
2838-
__gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
2839-
return
2840-
;;
2841-
mergetool.*.*)
2842-
local pfx="${cur_%.*}."
2843-
cur_="${cur_##*.}"
2844-
__gitcomp "cmd path trustExitCode" "$pfx" "$cur_" "$sfx"
2846+
__git_compute_first_level_config_vars_for_section "${section}"
2847+
local this_section="__git_first_level_config_vars_for_section_${section}"
2848+
__gitcomp_nl_append "${!this_section}" "$pfx" "$cur_" "${sfx:- }"
28452849
return
28462850
;;
28472851
pager.*)
28482852
local pfx="${cur_%.*}."
28492853
cur_="${cur_#*.}"
28502854
__git_compute_all_commands
2851-
__gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "${sfx- }"
2852-
return
2853-
;;
2854-
remote.*.*)
2855-
local pfx="${cur_%.*}."
2856-
cur_="${cur_##*.}"
2857-
__gitcomp "
2858-
url proxy fetch push mirror skipDefaultUpdate
2859-
receivepack uploadpack tagOpt pushurl
2860-
" "$pfx" "$cur_" "$sfx"
2855+
__gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "${sfx:- }"
28612856
return
28622857
;;
28632858
remote.*)
28642859
local pfx="${cur_%.*}."
28652860
cur_="${cur_#*.}"
2861+
local section="${pfx%.}"
28662862
__gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
2867-
__gitcomp_nl_append "pushDefault" "$pfx" "$cur_" "${sfx- }"
2863+
__git_compute_first_level_config_vars_for_section "${section}"
2864+
local this_section="__git_first_level_config_vars_for_section_${section}"
2865+
__gitcomp_nl_append "${!this_section}" "$pfx" "$cur_" "${sfx:- }"
28682866
return
28692867
;;
2870-
url.*.*)
2868+
submodule.*)
28712869
local pfx="${cur_%.*}."
2872-
cur_="${cur_##*.}"
2873-
__gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_" "$sfx"
2870+
cur_="${cur_#*.}"
2871+
local section="${pfx%.}"
2872+
__gitcomp_nl "$(__git config -f "$(__git rev-parse --show-toplevel)/.gitmodules" --get-regexp 'submodule.*.path' | awk -F. '{print $2}')" "$pfx" "$cur_" "."
2873+
__git_compute_first_level_config_vars_for_section "${section}"
2874+
local this_section="__git_first_level_config_vars_for_section_${section}"
2875+
__gitcomp_nl_append "${!this_section}" "$pfx" "$cur_" "${sfx:- }"
28742876
return
28752877
;;
28762878
*.*)

t/t9902-completion.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2724,6 +2724,35 @@ test_expect_success 'git config - variable name include' '
27242724
EOF
27252725
'
27262726

2727+
test_expect_success 'setup for git config submodule tests' '
2728+
test_create_repo sub &&
2729+
test_commit -C sub initial &&
2730+
git submodule add ./sub
2731+
'
2732+
2733+
test_expect_success 'git config - variable name - submodule and __git_compute_first_level_config_vars_for_section' '
2734+
test_completion "git config submodule." <<-\EOF
2735+
submodule.active Z
2736+
submodule.alternateErrorStrategy Z
2737+
submodule.alternateLocation Z
2738+
submodule.fetchJobs Z
2739+
submodule.propagateBranches Z
2740+
submodule.recurse Z
2741+
submodule.sub.Z
2742+
EOF
2743+
'
2744+
2745+
test_expect_success 'git config - variable name - __git_compute_second_level_config_vars_for_section' '
2746+
test_completion "git config submodule.sub." <<-\EOF
2747+
submodule.sub.url Z
2748+
submodule.sub.update Z
2749+
submodule.sub.branch Z
2750+
submodule.sub.fetchRecurseSubmodules Z
2751+
submodule.sub.ignore Z
2752+
submodule.sub.active Z
2753+
EOF
2754+
'
2755+
27272756
test_expect_success 'git config - value' '
27282757
test_completion "git config color.pager " <<-\EOF
27292758
false Z

0 commit comments

Comments
 (0)