Skip to content

Commit

Permalink
bash: complete full refs
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
SZEDER Gábor authored and Junio C Hamano committed Nov 28, 2008
1 parent 76bac89 commit 608efb8
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions contrib/completion/git-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,22 @@ __git_tags ()

__git_refs ()
{
local cmd i is_hash=y dir="$(__gitdir "$1")"
local i is_hash=y dir="$(__gitdir "$1")"
local cur="${COMP_WORDS[COMP_CWORD]}" format refs
if [ -d "$dir" ]; then
if [ -e "$dir/HEAD" ]; then echo HEAD; fi
git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
refs/tags refs/heads refs/remotes
case "$cur" in
refs|refs/*)
format="refname"
refs="${cur%/*}"
;;
*)
if [ -e "$dir/HEAD" ]; then echo HEAD; fi
format="refname:short"
refs="refs/tags refs/heads refs/remotes"
;;
esac
git --git-dir="$dir" for-each-ref --format="%($format)" \
$refs
return
fi
for i in $(git ls-remote "$dir" 2>/dev/null); do
Expand Down

0 comments on commit 608efb8

Please sign in to comment.