File tree Expand file tree Collapse file tree 2 files changed +48
-24
lines changed Expand file tree Collapse file tree 2 files changed +48
-24
lines changed Original file line number Diff line number Diff line change @@ -739,30 +739,25 @@ __git_compute_porcelain_commands ()
739
739
__git_porcelain_commands=$( __git_list_porcelain_commands)
740
740
}
741
741
742
+ # Lists all set config variables starting with the given section prefix,
743
+ # with the prefix removed.
744
+ __git_get_config_variables ()
745
+ {
746
+ local section=" $1 " i IFS=$' \n '
747
+ for i in $( git --git-dir=" $( __gitdir) " config --get-regexp " ^$section \..*" 2> /dev/null) ; do
748
+ i=" ${i# $section .} "
749
+ echo " ${i/ */ } "
750
+ done
751
+ }
752
+
742
753
__git_pretty_aliases ()
743
754
{
744
- local i IFS=$' \n '
745
- for i in $( git --git-dir=" $( __gitdir) " config --get-regexp " pretty\..*" 2> /dev/null) ; do
746
- case " $i " in
747
- pretty.* )
748
- i=" ${i# pretty.} "
749
- echo " ${i/ */ } "
750
- ;;
751
- esac
752
- done
755
+ __git_get_config_variables " pretty"
753
756
}
754
757
755
758
__git_aliases ()
756
759
{
757
- local i IFS=$' \n '
758
- for i in $( git --git-dir=" $( __gitdir) " config --get-regexp " alias\..*" 2> /dev/null) ; do
759
- case " $i " in
760
- alias.* )
761
- i=" ${i# alias.} "
762
- echo " ${i/ */ } "
763
- ;;
764
- esac
765
- done
760
+ __git_get_config_variables " alias"
766
761
}
767
762
768
763
# __git_aliased_command requires 1 argument
@@ -2260,12 +2255,7 @@ _git_remote ()
2260
2255
__git_complete_remote_or_refspec
2261
2256
;;
2262
2257
update)
2263
- local i c=' ' IFS=$' \n '
2264
- for i in $( git --git-dir=" $( __gitdir) " config --get-regexp " remotes\..*" 2> /dev/null) ; do
2265
- i=" ${i# remotes.} "
2266
- c=" $c ${i/ */ } "
2267
- done
2268
- __gitcomp " $c "
2258
+ __gitcomp " $( __git_get_config_variables " remotes" ) "
2269
2259
;;
2270
2260
* )
2271
2261
;;
Original file line number Diff line number Diff line change @@ -370,6 +370,40 @@ test_expect_success '__git_remotes - list remotes from $GIT_DIR/remotes and from
370
370
test_cmp expect actual
371
371
'
372
372
373
+ test_expect_success ' __git_get_config_variables' '
374
+ cat >expect <<-EOF &&
375
+ name-1
376
+ name-2
377
+ EOF
378
+ test_config interesting.name-1 good &&
379
+ test_config interesting.name-2 good &&
380
+ test_config subsection.interesting.name-3 bad &&
381
+ __git_get_config_variables interesting >actual &&
382
+ test_cmp expect actual
383
+ '
384
+
385
+ test_expect_success ' __git_pretty_aliases' '
386
+ cat >expect <<-EOF &&
387
+ author
388
+ hash
389
+ EOF
390
+ test_config pretty.author "%an %ae" &&
391
+ test_config pretty.hash %H &&
392
+ __git_pretty_aliases >actual &&
393
+ test_cmp expect actual
394
+ '
395
+
396
+ test_expect_success ' __git_aliases' '
397
+ cat >expect <<-EOF &&
398
+ ci
399
+ co
400
+ EOF
401
+ test_config alias.ci commit &&
402
+ test_config alias.co checkout &&
403
+ __git_aliases >actual &&
404
+ test_cmp expect actual
405
+ '
406
+
373
407
test_expect_success ' basic' '
374
408
run_completion "git " &&
375
409
# built-in
You can’t perform that action at this time.
0 commit comments