Skip to content

Commit aed3881

Browse files
szedergitster
authored andcommitted
completion: support excluding full refs
Commit 49416ad (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>
1 parent aa0644f commit aed3881

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

contrib/completion/git-completion.bash

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,17 +387,17 @@ __git_refs ()
387387
fi
388388

389389
if [ "$list_refs_from" = path ]; then
390+
if [[ "$cur_" == ^* ]]; then
391+
pfx="^"
392+
cur_=${cur_#^}
393+
fi
390394
case "$cur_" in
391395
refs|refs/*)
392396
format="refname"
393397
refs="${cur_%/*}"
394398
track=""
395399
;;
396400
*)
397-
if [[ "$cur_" == ^* ]]; then
398-
pfx="^"
399-
cur_=${cur_#^}
400-
fi
401401
for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
402402
if [ -e "$dir/$i" ]; then echo $pfx$i; fi
403403
done

t/t9902-completion.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,37 @@ test_expect_success '__git_refs - after --opt= - full refs' '
806806
test_cmp expected "$actual"
807807
'
808808

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+
809840
test_expect_success '__git_complete_refs - simple' '
810841
sed -e "s/Z$//" >expected <<-EOF &&
811842
HEAD Z

0 commit comments

Comments
 (0)