Skip to content

Commit 35e65ec

Browse files
spearceJunio C Hamano
authored andcommitted
Support bash completion of refs/remote.
Now that people are really likely to start using separate remotes (due to the default in git-clone changing) we should support ref completion for these refs in as many commands as possible. While we are working on this routine we should use for-each-ref to obtain a list of local refs, as this should run faster than peek-remote as it does not need to dereference tag objects in order to produce the list of refs back to us. It should also be more friendly to users of StGIT as we won't generate a list of the StGIT metadata refs. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 6e31b86 commit 35e65ec

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

contrib/completion/git-completion.bash

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,26 @@ __git_refs ()
4747
{
4848
local cmd i is_hash=y dir="${1:-$(__gitdir)}"
4949
if [ -d "$dir" ]; then
50-
cmd=git-peek-remote
51-
else
52-
cmd=git-ls-remote
50+
if [ -e "$dir/HEAD" ]; then echo HEAD; fi
51+
for i in $(git --git-dir="$dir" \
52+
for-each-ref --format='%(refname)' \
53+
refs/tags refs/heads refs/remotes); do
54+
case "$i" in
55+
refs/tags/*) echo "${i#refs/tags/}" ;;
56+
refs/heads/*) echo "${i#refs/heads/}" ;;
57+
refs/remotes/*) echo "${i#refs/remotes/}" ;;
58+
*) echo "$i" ;;
59+
esac
60+
done
61+
return
5362
fi
54-
for i in $($cmd "$dir" 2>/dev/null); do
63+
for i in $(git-ls-remote "$dir" 2>/dev/null); do
5564
case "$is_hash,$i" in
5665
y,*) is_hash=n ;;
5766
n,*^{}) is_hash=y ;;
5867
n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
5968
n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
69+
n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
6070
n,*) is_hash=y; echo "$i" ;;
6171
esac
6272
done

0 commit comments

Comments
 (0)