From 07d6f75fa751361f6fd9d5f35155fb2885402a87 Mon Sep 17 00:00:00 2001 From: Matt Hunter Date: Mon, 1 Jun 2026 03:30:15 -0400 Subject: Fix %{alert} not rendering when upstream is missing Though the command used to initialize $upstream_name will return a failed exit code when where is not a upstream branch available, that command will still echo its argument to stdout, which ends up in our variable. This ends up not breaking most usage of the value, as it doesn't contain a real ref - but the [ -z "$upstream_name" ] check in element_alert would essentially never evaluate true. Handle failed cases by initializing $upstream_name with an empty string. Fixes: cee3f0443ff9 ("Bulk rewrite of git-sonar script") Signed-off-by: Matt Hunter --- git-sonar | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-sonar b/git-sonar index 5a41bbf..c44b1d5 100755 --- a/git-sonar +++ b/git-sonar @@ -73,7 +73,7 @@ PROMPT_COLOR="${GIT_SONAR_PROMPT_COLOR:-"$COLOR_GRAY"}" PROMPT_FORMAT="${GIT_SONAR_PROMPT_FORMAT:-" ${PROMPT_COLOR}git:(${COLOR_DEF}%{alert}%{remote: }%{branch}%{ :local}${PROMPT_COLOR})${COLOR_DEF}%{ :stash}%{ :status}"}" # Gather information about the current git branch. -upstream_name="$(git rev-parse --abbrev-ref '@{upstream}' 2>/dev/null)" +upstream_name="$(git rev-parse --abbrev-ref '@{upstream}' 2>/dev/null)" || upstream_name="" branch_name="$(git symbolic-ref --short HEAD 2>/dev/null)" commit_hash="$(git rev-parse --short HEAD 2>/dev/null)" -- cgit v1.2.3