Skip to content

Commit abf0598

Browse files
szedergitster
authored andcommitted
completion: make refs completion consistent for local and remote repos
For a local repository the __git_refs() completion helper function lists refs under 'refs/(tags|heads|remotes)/', plus some special refs like HEAD and ORIG_HEAD. For a remote repository, however, it lists all refs. Fix this inconsistency by specifying refs filter patterns for 'git ls-remote' to only list refs under 'refs/(tags|heads|remotes)/'. For now this makes it impossible to complete refs outside of 'refs/(tags|heads|remotes)/' in a remote repository, but a followup patch will resurrect that. Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a31e626 commit abf0598

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

contrib/completion/git-completion.bash

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -616,13 +616,11 @@ __git_refs ()
616616
fi
617617
return
618618
fi
619-
for i in $(git ls-remote "$dir" 2>/dev/null); do
619+
for i in $(git ls-remote "$dir" HEAD ORIG_HEAD 'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev/null); do
620620
case "$is_hash,$i" in
621621
y,*) is_hash=n ;;
622622
n,*^{}) is_hash=y ;;
623-
n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
624-
n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
625-
n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
623+
n,refs/*) is_hash=y; echo "${i#refs/*/}" ;;
626624
n,*) is_hash=y; echo "$i" ;;
627625
esac
628626
done

0 commit comments

Comments
 (0)