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

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

From
D. Ben Knoble <ben.knoble@gmail.com>
Date
Nov 20, 2025, 16:01 UTC
Message-ID
<CALnO6CBzE-+51LfgjpEv665oG6kZG9_4YZTv8qgqtNrhh+a-Bw@mail.gmail.com>
In-Reply-To
<39b17bc64ff0d2e4162437ab745845c055315037.1763232863.git.gitgitgadget@gmail.com>

On Sat, Nov 15, 2025 at 1:55 PM Kiril Ivanov via GitGitGadget <gitgitgadget@gmail.com> wrote:

Show 22 quoted lines
> 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
> @@ -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  }" ;;

I generally advise avoiding "X && Y || Z" as a replacement for "if X; then Y; else Z; fi" because if X succeeds and Y fails, Z runs in the former but not the latter.

Here, Y is an infallible (?) assignment, so we should not have any issues. OTOH, such subtleties may teach novice readers the wrong lesson ("oh, handy shortcut!" vs "I see how this works in restricted cases"). Using "if" is a bit more invasive wrt to the patch, but would be clearer to me.

Our coding style also prefers "test" to "[".
-- 
D. Ben Knoble
Previous: Kiril Ivanov via GitGitGadgetNext: Eric Sunshine
Message 5 of 10 in “git-prompt: add quiet upstream indicator option”
  1. 0/3 git-prompt: add quiet upstream indicator optionKiril Ivanov via GitGitGadget, Nov 15, 2025
  2. 1/3 t9903: shorten setup using test_commitKiril Ivanov via GitGitGadget, Nov 15, 2025
  3. 2/3 t9903: add upstream indicator testsKiril Ivanov via GitGitGadget, Nov 15, 2025
  4. 3/3 git-prompt: add quiet upstream indicator optionKiril Ivanov via GitGitGadget, Nov 15, 2025
  5. D. Ben KnobleNov 20, 2025
  6. Eric SunshineNov 20, 2025
  7. D. Ben KnobleNov 20, 2025
  8. Junio C HamanoNov 15, 2025
  9. Kiril IvanovNov 16, 2025
  10. Junio C HamanoNov 16, 2025

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.