Fix git capsule fallback when __git_ps1 is empty

This commit is contained in:
2026-01-24 14:03:33 +00:00
parent 4bd8307bf0
commit 5ed49cc54c
2 changed files with 6 additions and 2 deletions

View File

@@ -432,6 +432,6 @@
"On macOS, installer is per-user and sources from .bashrc/.bash_profile.", "On macOS, installer is per-user and sources from .bashrc/.bash_profile.",
"Seasonal palettes and contest pack are now documented directly in main.", "Seasonal palettes and contest pack are now documented directly in main.",
"README uses images/bash-pallete.png.", "README uses images/bash-pallete.png.",
"Git capsule prefers __git_ps1 and falls back to git symbolic-ref/short hash when git-prompt is unavailable." "Git capsule prefers __git_ps1 and falls back to git symbolic-ref/short hash when git-prompt is unavailable or returns empty."
] ]
} }

View File

@@ -169,7 +169,11 @@ __git_capsule() {
if declare -F __git_ps1 >/dev/null 2>&1; then if declare -F __git_ps1 >/dev/null 2>&1; then
has_ps1=1 has_ps1=1
info="$(__git_ps1 "%s" 2>/dev/null)" info="$(__git_ps1 "%s" 2>/dev/null)"
else if [[ -z "$info" ]]; then
has_ps1=0
fi
fi
if [[ -z "$info" ]]; then
if command -v git >/dev/null 2>&1; then if command -v git >/dev/null 2>&1; then
info="$(git symbolic-ref --quiet --short HEAD 2>/dev/null || git rev-parse --short HEAD 2>/dev/null)" info="$(git symbolic-ref --quiet --short HEAD 2>/dev/null || git rev-parse --short HEAD 2>/dev/null)"
fi fi