From b2a09d2a5b73b23a74b24e66b3f37b512b3920f7 Mon Sep 17 00:00:00 2001 From: Matt Hunter Date: Sat, 28 Feb 2026 07:00:29 -0500 Subject: Add new prompt output element "missingups" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A previous behavior of the %{remote} prompt feature was to print something like "git:(upstream⚡branch)" if the branch had never been pushed to the remote. This patch addresses this case to both clean up the prompt appearance and change the semantics of this warning. In my own opinion, it is quite a normal workflow to be spinning off local-only branches, whether they are short lived or not, and giving a noisy warning that "branch" has no remote counterpart is distracting and counter productive. However, a situation that _is worth_ warning the user about is the case when a branch _has been pushed to a remote_ (eg: it has a remote and merge-target configured), but this remote counterpart branch was unexpectedly removed. This is when git-status says "Your branch is based on ..., but the upstream is gone." So, separate this specific warning into a new prompt feature: %{missingups} (missing upstream), which simply shows the lightning bolt character when a configured upstream branch is missing. Remove this case from %{remote}, which is now quiet when the upstream is removed (even if a remote-tracking branch is configured). This separation to a new element makes it possible to still see this warning if opting out of the remote-commits feature. Signed-off-by: Matt Hunter --- git-sonar | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/git-sonar b/git-sonar index 92a96c7..b996dd9 100755 --- a/git-sonar +++ b/git-sonar @@ -52,7 +52,7 @@ prepare_colors() { COLOR_BRANCH="\x01${GIT_RADAR_COLOR_BRANCH:-"\\033[0m"}\x02" MASTER_SYMBOL="${GIT_RADAR_MASTER_SYMBOL:-"\\x01\\033[0m\\x02\\xF0\\x9D\\x98\\xAE\\x01\\033[0m\\x02"}" - PROMPT_FORMAT="${GIT_RADAR_FORMAT:-" \\x01\\033[1;30m\\x02git:(\\x01\\033[0m\\x02%{remote: }%{condition}%{branch}%{ :local}\\x01\\033[1;30m\\x02)\\x01\\033[0m\\x02%{ :stash}%{ :changes}"}" + PROMPT_FORMAT="${GIT_RADAR_FORMAT:-" \\x01\\033[1;30m\\x02git:(\\x01\\033[0m\\x02%{remote: }%{condition}%{missingups}%{branch}%{ :local}\\x01\\033[1;30m\\x02)\\x01\\033[0m\\x02%{ :stash}%{ :changes}"}" RESET_COLOR_LOCAL="\x01${GIT_RADAR_COLOR_LOCAL_RESET:-"\\033[0m"}\x02" RESET_COLOR_REMOTE="\x01${GIT_RADAR_COLOR_REMOTE_RESET:-"\\033[0m"}\x02" @@ -372,11 +372,20 @@ color_local_commits() { printf $PRINT_F_OPTION "$local_commits" } +color_missing_upstream() { + local not_upstream="${COLOR_REMOTE_NOT_UPSTREAM}⚡$RESET_COLOR_REMOTE" + + if remote_branch="$(remote_branch_name)"; then + if ! git rev-parse "$remote_branch" -- >/dev/null 2>&1; then + printf "$not_upstream" + fi + fi +} + color_remote_commits() { local green_ahead_arrow="${COLOR_REMOTE_AHEAD}←$RESET_COLOR_REMOTE" local red_behind_arrow="${COLOR_REMOTE_BEHIND}→$RESET_COLOR_REMOTE" local yellow_diverged_arrow="${COLOR_REMOTE_DIVERGED}⇄$RESET_COLOR_REMOTE" - local not_upstream="${COLOR_REMOTE_NOT_UPSTREAM}⚡$RESET_COLOR_REMOTE" if remote_branch="$(remote_branch_name)"; then remote_ahead="$(remote_ahead_of_master "$remote_branch")" @@ -389,8 +398,6 @@ color_remote_commits() { elif [[ "$remote_behind" -gt "0" ]]; then remote="$MASTER_SYMBOL $remote_behind $red_behind_arrow" fi - else - remote="upstream $not_upstream" fi printf $PRINT_F_OPTION "$remote" @@ -438,6 +445,14 @@ render_prompt() { condition_sed="s/${sed_pre}condition${sed_post}//" fi fi + if [[ $PROMPT_FORMAT =~ ${if_pre}missingups${if_post} ]]; then + missingups_result="$(color_missing_upstream)" + if [[ -n "$missingups_result" ]]; then + missingups_sed="s/${sed_pre}missingups${sed_post}/\2${missingups_result}\4/" + else + missingups_sed="s/${sed_pre}missingups${sed_post}//" + fi + fi if [[ $PROMPT_FORMAT =~ ${if_pre}remote${if_post} ]]; then remote_result="$(color_remote_commits)" if [[ -n "$remote_result" ]]; then @@ -481,6 +496,7 @@ render_prompt() { printf '%b' "$PROMPT_FORMAT" | sed \ -e "$condition_sed" \ + -e "$missingups_sed" \ -e "$remote_sed" \ -e "$branch_sed" \ -e "$changes_sed" \ -- cgit v1.2.3