git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 3/4] git-prompt: make long upstream state indicator consistent

From
Justin Donnelly via GitGitGadget <gitgitgadget@gmail.com>
Date
Feb 27, 2022, 19:57 UTC
Message-ID
<0af083413b81eb393373b6fe02c5dd4c04d90bdd.1645991832.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1162.v2.git.1645991832.gitgitgadget@gmail.com>
From: Justin Donnelly <justinrdonnelly@gmail.com>

Use a pipe as a separator before long upstream state indicator. This is consistent with long state indicators for sparse and in-progress operations (e.g. merge).

For comparison, `__git_ps1` examples without upstream state indicator: (main) (main %) (main *%) (main|SPARSE) (main %|SPARSE) (main *%|SPARSE) (main|SPARSE|REBASE 1/2) (main %|SPARSE|REBASE 1/2)

Note that if there are long state indicators, they appear after short state indicators if there are any, or after the branch name if there are no short state indicators. Each long state indicator begins with a pipe (`|`) as a separator.

Before/after examples with long upstream state indicator:
| Before                          | After                           |
| ------------------------------- | ------------------------------- |
| (main u=)                       | (main|u=)                       |
| (main u= origin/main)           | (main|u= origin/main)           |
| (main u+1)                      | (main|u+1)                      |
| (main u+1 origin/main)          | (main|u+1 origin/main)          |
| (main % u=)                     | (main %|u=)                     |
| (main % u= origin/main)         | (main %|u= origin/main)         |
| (main % u+1)                    | (main %|u+1)                    |
| (main % u+1 origin/main)        | (main %|u+1 origin/main)        |
| (main|SPARSE u=)                | (main|SPARSE|u=)                |
| (main|SPARSE u= origin/main)    | (main|SPARSE|u= origin/main)    |
| (main|SPARSE u+1)               | (main|SPARSE|u+1)               |
| (main|SPARSE u+1 origin/main)   | (main|SPARSE|u+1 origin/main)   |
| (main %|SPARSE u=)              | (main %|SPARSE|u=)              |
| (main %|SPARSE u= origin/main)  | (main %|SPARSE|u= origin/main)  |
| (main %|SPARSE u+1)             | (main %|SPARSE|u+1)             |
| (main %|SPARSE u+1 origin/main) | (main %|SPARSE|u+1 origin/main) |
Signed-off-by: Justin Donnelly <justinrdonnelly@gmail.com>
---
 contrib/completion/git-prompt.sh | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 613389a53bc..2772f990888 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -109,7 +109,7 @@
 __git_printf_supports_v=
 printf -v __git_printf_supports_v -- '%s' yes >/dev/null 2>&1
 
-# stores the divergence from upstream in $p (for short status) or $upstream (for verbose status)
+# stores the divergence from upstream in $p
 # used by GIT_PS1_SHOWUPSTREAM
 __git_ps1_show_upstream ()
 {
@@ -219,13 +219,13 @@ __git_ps1_show_upstream ()
 		"") # no upstream
 			upstream="" ;;
 		"0	0") # equal to upstream
-			upstream=" u=" ;;
+			upstream="|u=" ;;
 		"0	"*) # ahead of upstream
-			upstream=" u+${count#0	}" ;;
+			upstream="|u+${count#0	}" ;;
 		*"	0") # behind upstream
-			upstream=" u-${count%	0}" ;;
+			upstream="|u-${count%	0}" ;;
 		*)	    # diverged from upstream
-			upstream=" u+${count#*	}-${count%	*}" ;;
+			upstream="|u+${count#*	}-${count%	*}" ;;
 		esac
 		if [[ -n "$count" && -n "$name" ]]; then
 			__git_ps1_upstream_name=$(git rev-parse \
-- 
gitgitgadget
Previous: Justin Donnelly via GitGitGadgetNext: Justin Donnelly via GitGitGadget
Message 12 of 15 in “In PS1 prompt, make upstream state indicators consistent with other state indicators”
  1. 0/4 In PS1 prompt, make upstream state indicators consistent with other state indicatorsJustin Donnelly via GitGitGadget, Feb 25, 2022
  2. 1/4 git-prompt: rename `upstream` to `upstream_type`Justin Donnelly via GitGitGadget, Feb 25, 2022
  3. 3/4 git-prompt: make long upstream state indicator consistentJustin Donnelly via GitGitGadget, Feb 25, 2022
  4. 2/4 git-prompt: make upstream state indicator location consistentJustin Donnelly via GitGitGadget, Feb 25, 2022
  5. 4/4 git-prompt: put upstream comments togetherJustin Donnelly via GitGitGadget, Feb 25, 2022
  6. Ævar Arnfjörð BjarmasonFeb 25, 2022
  7. Justin DonnellyFeb 27, 2022
  8. Ævar Arnfjörð BjarmasonFeb 27, 2022
  9. 0/4 In PS1 prompt, make upstream state indicators consistent with other state indicatorsJustin Donnelly via GitGitGadget, Feb 27, 2022
  10. 1/4 git-prompt: rename `upstream` to `upstream_type`Justin Donnelly via GitGitGadget, Feb 27, 2022
  11. 2/4 git-prompt: make upstream state indicator location consistentJustin Donnelly via GitGitGadget, Feb 27, 2022
  12. 3/4 git-prompt: make long upstream state indicator consistentJustin Donnelly via GitGitGadget, Feb 27, 2022
  13. 4/4 git-prompt: put upstream comments togetherJustin Donnelly via GitGitGadget, Feb 27, 2022
  14. Ævar Arnfjörð BjarmasonMar 22, 2022
  15. Junio C HamanoMar 23, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.