Skip to content

Commit 5af9d5f

Browse files
szedergitster
authored andcommitted
completion: complete config variables and values for 'git clone --config='
Completing configuration sections and variable names for the stuck argument of 'git clone --config=<TAB>' requires a bit of extra care compared to doing the same for the unstuck argument of 'git clone --config <TAB>', because we have to deal with that '--config=' being part of the current word to be completed. Add an option to the __git_complete_config_variable_name_and_value() and in turn to the __git_complete_config_variable_name() helper functions to specify the current section/variable name to be completed, so they can be used even when completing the stuck argument of '--config='. __git_complete_config_variable_value() already has such an option, and thus no further changes were necessary to complete possible values after 'git clone --config=section.name=<TAB>'. Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 88cd790 commit 5af9d5f

File tree

2 files changed

+70
-17
lines changed

2 files changed

+70
-17
lines changed

contrib/completion/git-completion.bash

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,11 @@ _git_clone ()
14061406
;;
14071407
esac
14081408
case "$cur" in
1409+
--config=*)
1410+
__git_complete_config_variable_name_and_value \
1411+
--cur="${cur##--config=}"
1412+
return
1413+
;;
14091414
--*)
14101415
__gitcomp_builtin clone
14111416
return
@@ -2352,84 +2357,97 @@ __git_complete_config_variable_value ()
23522357
# Completes configuration sections, subsections, variable names.
23532358
#
23542359
# Usage: __git_complete_config_variable_name [<option>]...
2360+
# --cur=<word>: The current configuration section/variable name to be
2361+
# completed. Defaults to the current word to be completed.
23552362
# --sfx=<suffix>: A suffix to be appended to each fully completed
23562363
# configuration variable name (but not to sections or
23572364
# subsections) instead of the default space.
23582365
__git_complete_config_variable_name ()
23592366
{
2360-
local sfx
2367+
local cur_="$cur" sfx
23612368

23622369
while test $# != 0; do
23632370
case "$1" in
2371+
--cur=*) cur_="${1##--cur=}" ;;
23642372
--sfx=*) sfx="${1##--sfx=}" ;;
23652373
*) return 1 ;;
23662374
esac
23672375
shift
23682376
done
23692377

2370-
case "$cur" in
2378+
case "$cur_" in
23712379
branch.*.*)
2372-
local pfx="${cur%.*}." cur_="${cur##*.}"
2380+
local pfx="${cur_%.*}."
2381+
cur_="${cur_##*.}"
23732382
__gitcomp "remote pushRemote merge mergeOptions rebase" "$pfx" "$cur_" "$sfx"
23742383
return
23752384
;;
23762385
branch.*)
2377-
local pfx="${cur%.*}." cur_="${cur#*.}"
2386+
local pfx="${cur%.*}."
2387+
cur_="${cur#*.}"
23782388
__gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
23792389
__gitcomp_nl_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "$sfx"
23802390
return
23812391
;;
23822392
guitool.*.*)
2383-
local pfx="${cur%.*}." cur_="${cur##*.}"
2393+
local pfx="${cur_%.*}."
2394+
cur_="${cur_##*.}"
23842395
__gitcomp "
23852396
argPrompt cmd confirm needsFile noConsole noRescan
23862397
prompt revPrompt revUnmerged title
23872398
" "$pfx" "$cur_" "$sfx"
23882399
return
23892400
;;
23902401
difftool.*.*)
2391-
local pfx="${cur%.*}." cur_="${cur##*.}"
2402+
local pfx="${cur_%.*}."
2403+
cur_="${cur_##*.}"
23922404
__gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
23932405
return
23942406
;;
23952407
man.*.*)
2396-
local pfx="${cur%.*}." cur_="${cur##*.}"
2408+
local pfx="${cur_%.*}."
2409+
cur_="${cur_##*.}"
23972410
__gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
23982411
return
23992412
;;
24002413
mergetool.*.*)
2401-
local pfx="${cur%.*}." cur_="${cur##*.}"
2414+
local pfx="${cur_%.*}."
2415+
cur_="${cur_##*.}"
24022416
__gitcomp "cmd path trustExitCode" "$pfx" "$cur_" "$sfx"
24032417
return
24042418
;;
24052419
pager.*)
2406-
local pfx="${cur%.*}." cur_="${cur#*.}"
2420+
local pfx="${cur_%.*}."
2421+
cur_="${cur_#*.}"
24072422
__git_compute_all_commands
24082423
__gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "$sfx"
24092424
return
24102425
;;
24112426
remote.*.*)
2412-
local pfx="${cur%.*}." cur_="${cur##*.}"
2427+
local pfx="${cur_%.*}."
2428+
cur_="${cur_##*.}"
24132429
__gitcomp "
24142430
url proxy fetch push mirror skipDefaultUpdate
24152431
receivepack uploadpack tagOpt pushurl
24162432
" "$pfx" "$cur_" "$sfx"
24172433
return
24182434
;;
24192435
remote.*)
2420-
local pfx="${cur%.*}." cur_="${cur#*.}"
2436+
local pfx="${cur_%.*}."
2437+
cur_="${cur_#*.}"
24212438
__gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
24222439
__gitcomp_nl_append "pushDefault" "$pfx" "$cur_" "$sfx"
24232440
return
24242441
;;
24252442
url.*.*)
2426-
local pfx="${cur%.*}." cur_="${cur##*.}"
2443+
local pfx="${cur_%.*}."
2444+
cur_="${cur_##*.}"
24272445
__gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_" "$sfx"
24282446
return
24292447
;;
24302448
*.*)
24312449
__git_compute_config_vars
2432-
__gitcomp "$__git_config_vars" "" "$cur" "$sfx"
2450+
__gitcomp "$__git_config_vars" "" "$cur_" "$sfx"
24332451
;;
24342452
*)
24352453
__git_compute_config_vars
@@ -2441,22 +2459,36 @@ __git_complete_config_variable_name ()
24412459
for (s in sections)
24422460
print s "."
24432461
}
2444-
')"
2462+
')" "" "$cur_"
24452463
;;
24462464
esac
24472465
}
24482466

24492467
# Completes '='-separated configuration sections/variable names and values
24502468
# for 'git -c section.name=value'.
2469+
#
2470+
# Usage: __git_complete_config_variable_name_and_value [<option>]...
2471+
# --cur=<word>: The current configuration section/variable name/value to be
2472+
# completed. Defaults to the current word to be completed.
24512473
__git_complete_config_variable_name_and_value ()
24522474
{
2453-
case "$cur" in
2475+
local cur_="$cur"
2476+
2477+
while test $# != 0; do
2478+
case "$1" in
2479+
--cur=*) cur_="${1##--cur=}" ;;
2480+
*) return 1 ;;
2481+
esac
2482+
shift
2483+
done
2484+
2485+
case "$cur_" in
24542486
*=*)
24552487
__git_complete_config_variable_value \
2456-
--varname="${cur%%=*}" --cur="${cur#*=}"
2488+
--varname="${cur_%%=*}" --cur="${cur_#*=}"
24572489
;;
24582490
*)
2459-
__git_complete_config_variable_name --sfx='='
2491+
__git_complete_config_variable_name --cur="$cur_" --sfx='='
24602492
;;
24612493
esac
24622494
}

t/t9902-completion.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,6 +1740,27 @@ test_expect_success 'git -c - value' '
17401740
EOF
17411741
'
17421742

1743+
test_expect_success 'git clone --config= - section' '
1744+
test_completion "git clone --config=br" <<-\EOF
1745+
branch.Z
1746+
browser.Z
1747+
EOF
1748+
'
1749+
1750+
test_expect_success 'git clone --config= - variable name' '
1751+
test_completion "git clone --config=log.d" <<-\EOF
1752+
log.date=Z
1753+
log.decorate=Z
1754+
EOF
1755+
'
1756+
1757+
test_expect_success 'git clone --config= - value' '
1758+
test_completion "git clone --config=color.pager=" <<-\EOF
1759+
false Z
1760+
true Z
1761+
EOF
1762+
'
1763+
17431764
test_expect_success 'sourcing the completion script clears cached commands' '
17441765
__git_compute_all_commands &&
17451766
verbose test -n "$__git_all_commands" &&

0 commit comments

Comments
 (0)