Skip to content

Commit 9ea8145

Browse files
committed
Merge branch 'ps/prompt-parse-HEAD-futureproof'
Futureproof command line prompt support (in contrib/). * ps/prompt-parse-HEAD-futureproof: git-prompt: stop manually parsing HEAD with unknown ref formats
2 parents 186b115 + fc134b4 commit 9ea8145

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

contrib/completion/git-prompt.sh

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ __git_ps1 ()
408408

409409
local repo_info rev_parse_exit_code
410410
repo_info="$(git rev-parse --git-dir --is-inside-git-dir \
411-
--is-bare-repository --is-inside-work-tree \
411+
--is-bare-repository --is-inside-work-tree --show-ref-format \
412412
--short HEAD 2>/dev/null)"
413413
rev_parse_exit_code="$?"
414414

@@ -421,6 +421,8 @@ __git_ps1 ()
421421
short_sha="${repo_info##*$'\n'}"
422422
repo_info="${repo_info%$'\n'*}"
423423
fi
424+
local ref_format="${repo_info##*$'\n'}"
425+
repo_info="${repo_info%$'\n'*}"
424426
local inside_worktree="${repo_info##*$'\n'}"
425427
repo_info="${repo_info%$'\n'*}"
426428
local bare_repo="${repo_info##*$'\n'}"
@@ -479,12 +481,25 @@ __git_ps1 ()
479481
b="$(git symbolic-ref HEAD 2>/dev/null)"
480482
else
481483
local head=""
482-
if ! __git_eread "$g/HEAD" head; then
483-
return $exit
484-
fi
485-
# is it a symbolic ref?
486-
b="${head#ref: }"
487-
if [ "$head" = "$b" ]; then
484+
485+
case "$ref_format" in
486+
files)
487+
if ! __git_eread "$g/HEAD" head; then
488+
return $exit
489+
fi
490+
491+
if [[ $head == "ref: "* ]]; then
492+
head="${head#ref: }"
493+
else
494+
head=""
495+
fi
496+
;;
497+
*)
498+
head="$(git symbolic-ref HEAD 2>/dev/null)"
499+
;;
500+
esac
501+
502+
if test -z "$head"; then
488503
detached=yes
489504
b="$(
490505
case "${GIT_PS1_DESCRIBE_STYLE-}" in
@@ -502,6 +517,8 @@ __git_ps1 ()
502517

503518
b="$short_sha..."
504519
b="($b)"
520+
else
521+
b="$head"
505522
fi
506523
fi
507524
fi

0 commit comments

Comments
 (0)