Skip to content

Commit 608efb8

Browse files
szedergitster
authored andcommitted
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>
1 parent 76bac89 commit 608efb8

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

contrib/completion/git-completion.bash

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,22 @@ __git_tags ()
188188

189189
__git_refs ()
190190
{
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
192193
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
196207
return
197208
fi
198209
for i in $(git ls-remote "$dir" 2>/dev/null); do

0 commit comments

Comments
 (0)