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