Subject: [PATCH 3/3] git-prompt: add quiet upstream indicator option

From: "Kiril Ivanov via GitGitGadget" <[email-masked]>
Date: Sat, 15 Nov 2025 18:54:23 +0000

From: Kiril Ivanov <[email-masked]>

Other single-char state indicators (e.g. stash, dirty) as well as
pipe-delimited indicators (e.g. '|CONFLICT') are only shown when
they are actionable.

OTOH, the upstream '=' (up-to-date with the upstream) is simply a
neutral state, which git-prompt is usually quiet about. Therefore,
allow users to hide it.

The 'verbose quiet' combination sounds weird but it may be what the
user wants, and does not conflict with anything else, so why not.

Signed-off-by: Kiril Ivanov <[email-masked]>
---
 contrib/completion/git-prompt.sh | 14 ++++++++++----
 t/t9903-bash-prompt.sh           | 10 +++++-----
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 6186c474ba..be23c522da 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -55,13 +55,14 @@
 # enabled.
 #
 # If you would like to see the difference between HEAD and its upstream,
-# set GIT_PS1_SHOWUPSTREAM="auto".  A "<" indicates you are behind, ">"
-# indicates you are ahead, "<>" indicates you have diverged and "="
-# indicates that there is no difference. You can further control
+# set GIT_PS1_SHOWUPSTREAM to a nonempty value.  A "<" indicates you are
+# behind, ">" indicates you are ahead, "<>" indicates you have diverged
+# and "=" indicates that there is no difference.  You can further control
 # behaviour by setting GIT_PS1_SHOWUPSTREAM to a space-separated list
 # of values:
 #
 #     verbose       show number of commits ahead/behind (+/-) upstream
+#     quiet         omit '=' when there is no difference to the upstream
 #     name          if verbose, then also show the upstream abbrev name
 #     legacy        don't use the '--count' option available in recent
 #                   versions of git-rev-list
@@ -157,7 +158,7 @@ __git_ps1_show_upstream ()
 {
 	local key value
 	local svn_remotes="" svn_url_pattern="" count n
-	local upstream_type=git legacy="" verbose="" name=""
+	local upstream_type=git legacy="" verbose="" quiet="" name=""
 	local LF="$__git_LF"
 
 	# get some config options from git-config
@@ -187,6 +188,7 @@ __git_ps1_show_upstream ()
 		case "$option" in
 		git|svn) upstream_type="$option" ;;
 		verbose) verbose=1 ;;
+		quiet)   quiet=1   ;;
 		legacy)  legacy=1  ;;
 		name)    name=1 ;;
 		esac
@@ -262,6 +264,8 @@ __git_ps1_show_upstream ()
 		"") # no upstream
 			p="" ;;
 		"0	0") # equal to upstream
+			[ "$quiet" ] &&
+			p="" ||
 			p="=" ;;
 		"0	"*) # ahead of upstream
 			p=">" ;;
@@ -275,6 +279,8 @@ __git_ps1_show_upstream ()
 		"") # no upstream
 			upstream="" ;;
 		"0	0") # equal to upstream
+			[ "$quiet" ] &&
+			upstream="|u" ||
 			upstream="|u=" ;;
 		"0	"*) # ahead of upstream
 			upstream="|u+${count#0	}" ;;
diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh
index 3997012d1c..855428f007 100755
--- a/t/t9903-bash-prompt.sh
+++ b/t/t9903-bash-prompt.sh
@@ -520,11 +520,11 @@ test_expect_success 'prompt - untracked files status indicator - not shown insid
 
 ################################################################
 # Show Upstream
-options=(          short  verbose   'verbose name'    )
-expected_equal=(   ' ='   '|u='     '|u= origin/main' )
-expected_ahead=(   ' >'   '|u+1'    '|u+1 origin/main')
-expected_behind=(  ' <'   '|u-1'    '|u-1 origin/b1'  )
-expected_diverged=(' <>'  '|u+1-1'  '|u+1-1 origin/b1')
+options=(          short  verbose   'verbose name'      quiet   'verbose quiet'  'verbose name quiet')
+expected_equal=(   ' ='   '|u='     '|u= origin/main'   ''      '|u'             '|u origin/main'    )
+expected_ahead=(   ' >'   '|u+1'    '|u+1 origin/main'  ' >'    '|u+1'           '|u+1 origin/main'  )
+expected_behind=(  ' <'   '|u-1'    '|u-1 origin/b1'    ' <'    '|u-1'           '|u-1 origin/b1'    )
+expected_diverged=(' <>'  '|u+1-1'  '|u+1-1 origin/b1'  ' <>'   '|u+1-1'         '|u+1-1 origin/b1'  )
 
 for i in ${!options[@]}
 do
-- 
gitgitgadget