completion: support excluding refs

Allow completion of refs with a ^ prefix. This allows completion of commands like 'git log HEAD ^origin/master'. Signed-off-by: Chris Packham <judge.packham@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Chris Packham committed Aug 24, 2016 at 20:41 UTC 49416ad22aa917178f306859a5bab60311166a9f
1 file changed +4 -3
contrib/completion/git-completion.bash
+4 -3
@@ -338,7 +338,7 @@ __git_tags ()
338 __git_refs ()
339 {
340 local i hash dir="$(__gitdir "${1-}")" track="${2-}"
341 - local format refs
341 + local format refs pfx
342 if [ -d "$dir" ]; then
343 case "$cur" in
344 refs|refs/*)
@@ -347,14 +347,15 @@ __git_refs ()
347 track=""
348 ;;
349 *)
350 + [[ "$cur" == ^* ]] && pfx="^"
351 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
351 - if [ -e "$dir/$i" ]; then echo $i; fi
352 + if [ -e "$dir/$i" ]; then echo $pfx$i; fi
353 done
354 format="refname:short"
355 refs="refs/tags refs/heads refs/remotes"
356 ;;
357 esac
357 - git --git-dir="$dir" for-each-ref --format="%($format)" \
358 + git --git-dir="$dir" for-each-ref --format="$pfx%($format)" \
359 $refs
360 if [ -n "$track" ]; then
361 # employ the heuristic used by git checkout