We're manually parsing the HEAD reference in git-prompt to figure out whether it is a symbolic or direct reference. This makes it intimately tied to the on-disk format we use to store references and will stop working once we gain additional reference backends in the Git project. Refactor the code to always use git-symbolic-ref(1) to read HEAD, which is both simpler and compatible with alternate reference backends. Signed-off-by: Patrick Steinhardt <ps@xxxxxx> --- contrib/completion/git-prompt.sh | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh index 2c030050ae..05de540e13 100644 --- a/contrib/completion/git-prompt.sh +++ b/contrib/completion/git-prompt.sh @@ -474,17 +474,10 @@ __git_ps1 () if [ -n "$b" ]; then : - elif [ -h "$g/HEAD" ]; then - # symlink symbolic ref - b="$(git symbolic-ref HEAD 2>/dev/null)" else - local head="" - if ! __git_eread "$g/HEAD" head; then - return $exit - fi - # is it a symbolic ref? - b="${head#ref: }" - if [ "$head" = "$b" ]; then + b="$(git symbolic-ref HEAD 2>/dev/null)" + + if test -z "$b"; then detached=yes b="$( case "${GIT_PS1_DESCRIBE_STYLE-}" in @@ -498,9 +491,14 @@ __git_ps1 () git describe HEAD ;; (* | default) git describe --tags --exact-match HEAD ;; - esac 2>/dev/null)" || + esac 2>/dev/null)" + + if test -z "$b"; then + test -z "$short_sha" && return $exit + + b="$short_sha..." + fi - b="$short_sha..." b="($b)" fi fi -- 2.43.0
Attachment:
signature.asc
Description: PGP signature