completion: add 'symbolic-ref'

Even 'symbolic-ref' is only completed when GIT_COMPLETION_SHOW_ALL_COMMANDS=1 is set, it currently defaults to completing file names, which is not very helpful. Add a simple completion function which completes options and refs. Signed-off-by: Roland Hieber <rhi@pengutronix.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Roland Hieber committed Apr 25, 2024 at 12:18 UTC cb85fdf4a4445fd201133dfc8d1e43c7e2e68bf5
2 files changed +34
contrib/completion/git-completion.bash
+11
@@ -3523,6 +3523,17 @@ _git_svn ()
3523 fi
3524 }
3525
3526 +_git_symbolic_ref () {
3527 + case "$cur" in
3528 + --*)
3529 + __gitcomp_builtin symbolic-ref
3530 + return
3531 + ;;
3532 + esac
3533 +
3534 + __git_complete_refs
3535 +}
3536 +
3537 _git_tag ()
3538 {
3539 local i c="$__git_cmd_idx" f=0
t/t9902-completion.sh
+23
@@ -2495,6 +2495,29 @@ test_expect_success 'complete tree filename with metacharacters' '
2495 EOF
2496 '
2497
2498 +test_expect_success 'symbolic-ref completes builtin options' '
2499 + test_completion "git symbolic-ref --d" <<-\EOF
2500 + --delete Z
2501 + EOF
2502 +'
2503 +
2504 +test_expect_success 'symbolic-ref completes short ref names' '
2505 + test_completion "git symbolic-ref foo m" <<-\EOF
2506 + main Z
2507 + mybranch Z
2508 + mytag Z
2509 + EOF
2510 +'
2511 +
2512 +test_expect_success 'symbolic-ref completes full ref names' '
2513 + test_completion "git symbolic-ref foo refs/" <<-\EOF
2514 + refs/heads/main Z
2515 + refs/heads/mybranch Z
2516 + refs/tags/mytag Z
2517 + refs/tags/A Z
2518 + EOF
2519 +'
2520 +
2521 test_expect_success PERL 'send-email' '
2522 test_completion "git send-email --cov" <<-\EOF &&
2523 --cover-from-description=Z