completion: expand "push --delete <remote> <ref>" for refs on that <remote>

Change the completion of "push --delete <remote> <ref>" to complete
refs on that <remote>, not all refs.

Before this cloning git.git and doing "git push --delete origin
p<TAB>" will complete nothing, since a fresh clone of git.git will
have no "pu" branch, whereas origin/p<TAB> will uselessly complete
origin/pu, but fully qualified references aren't accepted by
"--delete".

Now p<TAB> will complete as "pu". The completion of giving --delete
later, e.g. "git push origin --delete p<TAB>" remains unchanged, this
is a bug, but is a general existing limitation of the bash completion,
and not how git-push is documented, so I'm not fixing that case, but
adding a failing TODO test for it.

The testing code was supplied by SZEDER Gábor in
<20170421122832.24617-1-szeder.dev@gmail.com> with minor setup
modifications on my part.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Reviewed-by: SZEDER Gábor <szeder.dev@gmail.com>
Test-code-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Ævar Arnfjörð Bjarmason 2017-04-22 17:55:04 +00:00 committed by Junio C Hamano
parent 584f8975d2
commit 723c1d526f
2 changed files with 35 additions and 0 deletions

View File

@ -709,6 +709,7 @@ __git_complete_remote_or_refspec ()
i="${words[c]}"
case "$i" in
--mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
-d|--delete) [ "$cmd" = "push" ] && lhs=0 ;;
--all)
case "$cmd" in
push) no_complete_refspec=1 ;;

View File

@ -1457,4 +1457,38 @@ test_expect_failure 'complete with tilde expansion' '
test_completion "git add ~/tmp/" "~/tmp/file"
'
test_expect_success 'setup other remote for remote reference completion' '
git remote add other otherrepo &&
git fetch other
'
for flag in -d --delete
do
test_expect_success "__git_complete_remote_or_refspec - push $flag other" '
sed -e "s/Z$//" >expected <<-EOF &&
master-in-other Z
EOF
(
words=(git push '$flag' other ma) &&
cword=${#words[@]} cur=${words[cword-1]} &&
__git_complete_remote_or_refspec &&
print_comp
) &&
test_cmp expected out
'
test_expect_failure "__git_complete_remote_or_refspec - push other $flag" '
sed -e "s/Z$//" >expected <<-EOF &&
master-in-other Z
EOF
(
words=(git push other '$flag' ma) &&
cword=${#words[@]} cur=${words[cword-1]} &&
__git_complete_remote_or_refspec &&
print_comp
) &&
test_cmp expected out
'
done
test_done