Skip to content

Commit cb85fdf

Browse files
rohiebgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3c2a3fd commit cb85fdf

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

contrib/completion/git-completion.bash

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3523,6 +3523,17 @@ _git_svn ()
35233523
fi
35243524
}
35253525

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+
35263537
_git_tag ()
35273538
{
35283539
local i c="$__git_cmd_idx" f=0

t/t9902-completion.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,6 +2495,29 @@ test_expect_success 'complete tree filename with metacharacters' '
24952495
EOF
24962496
'
24972497

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+
24982521
test_expect_success PERL 'send-email' '
24992522
test_completion "git send-email --cov" <<-\EOF &&
25002523
--cover-from-description=Z

0 commit comments

Comments
 (0)