public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: "Kiril Ivanov via GitGitGadget" <gitgitgadget@gmail•com>
To: git@vger•kernel.org
Cc: Kiril Ivanov <ivanovkirilg@gmail•com>,
	Kiril Ivanov <ivanovkirilg@gmail•com>
Subject: [PATCH 3/3] git-prompt: add quiet upstream indicator option
Date: Sat, 15 Nov 2025 18:54:23 +0000	[thread overview]
Message-ID: <39b17bc64ff0d2e4162437ab745845c055315037.1763232863.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2101.git.git.1763232863.gitgitgadget@gmail.com>

From: Kiril Ivanov <ivanovkirilg@gmail•com>

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 <ivanovkirilg@gmail•com>
---
 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

  parent reply	other threads:[~2025-11-15 18:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-15 18:54 [PATCH 0/3] git-prompt: add quiet upstream indicator option Kiril Ivanov via GitGitGadget
2025-11-15 18:54 ` [PATCH 1/3] t9903: shorten setup using test_commit Kiril Ivanov via GitGitGadget
2025-11-15 18:54 ` [PATCH 2/3] t9903: add upstream indicator tests Kiril Ivanov via GitGitGadget
2025-11-15 18:54 ` Kiril Ivanov via GitGitGadget [this message]
2025-11-20 16:01   ` [PATCH 3/3] git-prompt: add quiet upstream indicator option D. Ben Knoble
2025-11-20 18:05     ` Eric Sunshine
2025-11-20 18:18       ` D. Ben Knoble
2025-11-15 20:07 ` [PATCH 0/3] " Junio C Hamano
2025-11-16 12:05   ` Kiril Ivanov
2025-11-16 16:55     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=39b17bc64ff0d2e4162437ab745845c055315037.1763232863.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=ivanovkirilg@gmail$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox