completion: support excluding full refs

Commit 49416ad22 (completion: support excluding refs, 2016-08-24) made possible to complete short refs with a '^' prefix. Extend the support to full refs to make completing '^refs/...' work. Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

SZEDER Gábor committed Mar 23, 2017 at 16:29 UTC aed3881359027921afffae2c6da853034a42c64d
2 files changed +35 -4
contrib/completion/git-completion.bash
+4 -4
@@ -387,6 +387,10 @@ __git_refs ()
387 fi
388
389 if [ "$list_refs_from" = path ]; then
390 + if [[ "$cur_" == ^* ]]; then
391 + pfx="^"
392 + cur_=${cur_#^}
393 + fi
394 case "$cur_" in
395 refs|refs/*)
396 format="refname"
@@ -394,10 +398,6 @@ __git_refs ()
398 track=""
399 ;;
400 *)
397 - if [[ "$cur_" == ^* ]]; then
398 - pfx="^"
399 - cur_=${cur_#^}
400 - fi
401 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
402 if [ -e "$dir/$i" ]; then echo $pfx$i; fi
403 done
t/t9902-completion.sh
+31
@@ -806,6 +806,37 @@ test_expect_success '__git_refs - after --opt= - full refs' '
806 test_cmp expected "$actual"
807 '
808
809 +test_expect_success '__git refs - exluding refs' '
810 + cat >expected <<-EOF &&
811 + ^HEAD
812 + ^master
813 + ^matching-branch
814 + ^other/branch-in-other
815 + ^other/master-in-other
816 + ^matching-tag
817 + EOF
818 + (
819 + cur=^ &&
820 + __git_refs >"$actual"
821 + ) &&
822 + test_cmp expected "$actual"
823 +'
824 +
825 +test_expect_success '__git refs - exluding full refs' '
826 + cat >expected <<-EOF &&
827 + ^refs/heads/master
828 + ^refs/heads/matching-branch
829 + ^refs/remotes/other/branch-in-other
830 + ^refs/remotes/other/master-in-other
831 + ^refs/tags/matching-tag
832 + EOF
833 + (
834 + cur=^refs/ &&
835 + __git_refs >"$actual"
836 + ) &&
837 + test_cmp expected "$actual"
838 +'
839 +
840 test_expect_success '__git_complete_refs - simple' '
841 sed -e "s/Z$//" >expected <<-EOF &&
842 HEAD Z