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>
Shawn O. Pearce committed
Nov 27, 2006 at 03:42 UTC
35e65ecca78ceeca8eca72149e7546de94ed8607
1 file changed
+14
-4
contrib/completion/git-completion.bash
+14
-4
@@ -47,16 +47,26 @@ __git_refs ()
47
{
48
local cmd i is_hash=y dir="${1:-$(__gitdir)}"
49
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
62
fi
54
- for i in $($cmd "$dir" 2>/dev/null); do
63
+ for i in $(git-ls-remote "$dir" 2>/dev/null); do
64
case "$is_hash,$i" in
65
y,*) is_hash=n ;;
66
n,*^{}) is_hash=y ;;
67
n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
68
n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
69
+ n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
70
n,*) is_hash=y; echo "$i" ;;
71
esac
72
done