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>

Ævar Arnfjörð Bjarmason committed Apr 22, 2017 at 17:55 UTC 723c1d526faaee6fac9b804f4b97b148f450eb5d
2 files changed +35
contrib/completion/git-completion.bash
+1
@@ -709,6 +709,7 @@ __git_complete_remote_or_refspec ()
709 i="${words[c]}"
710 case "$i" in
711 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
712 + -d|--delete) [ "$cmd" = "push" ] && lhs=0 ;;
713 --all)
714 case "$cmd" in
715 push) no_complete_refspec=1 ;;
t/t9902-completion.sh
+34
@@ -1457,4 +1457,38 @@ test_expect_failure 'complete with tilde expansion' '
1457 test_completion "git add ~/tmp/" "~/tmp/file"
1458 '
1459
1460 +test_expect_success 'setup other remote for remote reference completion' '
1461 + git remote add other otherrepo &&
1462 + git fetch other
1463 +'
1464 +
1465 +for flag in -d --delete
1466 +do
1467 + test_expect_success "__git_complete_remote_or_refspec - push $flag other" '
1468 + sed -e "s/Z$//" >expected <<-EOF &&
1469 + master-in-other Z
1470 + EOF
1471 + (
1472 + words=(git push '$flag' other ma) &&
1473 + cword=${#words[@]} cur=${words[cword-1]} &&
1474 + __git_complete_remote_or_refspec &&
1475 + print_comp
1476 + ) &&
1477 + test_cmp expected out
1478 + '
1479 +
1480 + test_expect_failure "__git_complete_remote_or_refspec - push other $flag" '
1481 + sed -e "s/Z$//" >expected <<-EOF &&
1482 + master-in-other Z
1483 + EOF
1484 + (
1485 + words=(git push other '$flag' ma) &&
1486 + cword=${#words[@]} cur=${words[cword-1]} &&
1487 + __git_complete_remote_or_refspec &&
1488 + print_comp
1489 + ) &&
1490 + test_cmp expected out
1491 + '
1492 +done
1493 +
1494 test_done