Skip to content

Commit fa308cd

Browse files
committed
Merge branch 'cp/completion-negative-refs' into maint
The command-line completion script (in contrib/) learned to complete "git cmd ^mas<HT>" to complete the negative end of reference to "git cmd ^master". * cp/completion-negative-refs: completion: support excluding refs
2 parents bab32da + 49416ad commit fa308cd

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

contrib/completion/git-completion.bash

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ __git_tags ()
338338
__git_refs ()
339339
{
340340
local i hash dir="$(__gitdir "${1-}")" track="${2-}"
341-
local format refs
341+
local format refs pfx
342342
if [ -d "$dir" ]; then
343343
case "$cur" in
344344
refs|refs/*)
@@ -347,14 +347,15 @@ __git_refs ()
347347
track=""
348348
;;
349349
*)
350+
[[ "$cur" == ^* ]] && pfx="^"
350351
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
352353
done
353354
format="refname:short"
354355
refs="refs/tags refs/heads refs/remotes"
355356
;;
356357
esac
357-
git --git-dir="$dir" for-each-ref --format="%($format)" \
358+
git --git-dir="$dir" for-each-ref --format="$pfx%($format)" \
358359
$refs
359360
if [ -n "$track" ]; then
360361
# employ the heuristic used by git checkout

0 commit comments

Comments
 (0)