Skip to content

Commit dd42c2f

Browse files
committed
completion: enhance "current branch" display
Introduce GIT_PS1_DESCRIBE option you can set to "contains", "branch", or "describe" to tweak the way how a detached HEAD is described. The default behaviour is to describe only exact match with some tag (otherwise use the first 7 hexdigits) as before. Signed-off-by: Junio C Hamano <[email protected]>
1 parent ff790b6 commit dd42c2f

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

contrib/completion/git-completion.bash

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,21 @@ __git_ps1 ()
108108
fi
109109

110110
b="$(git symbolic-ref HEAD 2>/dev/null)" || {
111-
b="$(git describe --exact-match HEAD 2>/dev/null)" ||
111+
112+
b="$(
113+
case "${GIT_PS1_DESCRIBE_STYLE-}" in
114+
(contains)
115+
git describe --contains HEAD ;;
116+
(branch)
117+
git describe --contains --all HEAD ;;
118+
(describe)
119+
git describe HEAD ;;
120+
(* | default)
121+
git describe --exact-match HEAD ;;
122+
esac 2>/dev/null)" ||
123+
112124
b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
113125
b="unknown"
114-
115126
b="($b)"
116127
}
117128
fi

0 commit comments

Comments
 (0)