@matheusbsbs / matheus-bagliano / commits / 608efb875f
Fork 0

bash: complete full refs

Sometimes it's handy to complete full refs, e.g. the user has some refs outside of refs/{heads,remotes,tags} or the user wants to complete some git command's special refs (like 'git show refs/bisect/bad'). To do that, we check whether the ref to be completed starts with 'refs/' or is 'refs' (to reduce the risk of matching 'refs-'). If it does, then we offer full refs for completion; otherwise everything works as usual. This way the impact on the common case is fairly small (hopefully not many users have branches or tags starting with 'refs'), and in the special case the cost of typing out 'refs' is bearable. While at it, also remove the unused 'cmd' variable from '__git_refs'. Signed-off-by: SZEDER Gábor <szeder@ira.uka.de> Acked-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

SZEDER Gábor committed Nov 28, 2008 at 01:46 UTC 608efb875f89a946d5cb37b2dd4077132618e0e1
1 file changed +15 -4
contrib/completion/git-completion.bash
+15 -4
@@ -188,11 +188,22 @@ __git_tags ()
188
189 __git_refs ()
190 {
191 - local cmd i is_hash=y dir="$(__gitdir "$1")"
191 + local i is_hash=y dir="$(__gitdir "$1")"
192 + local cur="${COMP_WORDS[COMP_CWORD]}" format refs
193 if [ -d "$dir" ]; then
193 - if [ -e "$dir/HEAD" ]; then echo HEAD; fi
194 - git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
195 - refs/tags refs/heads refs/remotes
194 + case "$cur" in
195 + refs|refs/*)
196 + format="refname"
197 + refs="${cur%/*}"
198 + ;;
199 + *)
200 + if [ -e "$dir/HEAD" ]; then echo HEAD; fi
201 + format="refname:short"
202 + refs="refs/tags refs/heads refs/remotes"
203 + ;;
204 + esac
205 + git --git-dir="$dir" for-each-ref --format="%($format)" \
206 + $refs
207 return
208 fi
209 for i in $(git ls-remote "$dir" 2>/dev/null); do