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

Re: [PATCH] completion: Add space to PS1 when showing upstream

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 18, 2011, 20:01 UTC
Message-ID
<7vtyf0w63k.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20110318150222.GB26236@inocybe.localdomain>
Todd Zullinger <tmz@pobox.com> writes:
> Depending on whether other changes were present or displayed in PS1, the
> prompt may have lacked a space between the branch and the upstream
> marker.

The grossly misnamed __git_ps1_show_upstream that does not show anything but only sets variable $p gives a non-alphanumeric mnemonic (e.g. p=">") that is not ambiguous without an extra leading SP under non verbose mode to make things shorter, and in verbose mode the returned string comes its own leading SP, e.g. " u+" followed by number of commits. So why would you want an extra SP in front of that SP that already exists?

Show 8 quoted lines
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 0b0b913..e5af5f6 100755
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -312,6 +312,7 @@ __git_ps1 ()
>  		local f="$w$i$s$u"
> +		[[ -z $f ]] && p="${p:+ $p}"
>  		printf "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r$p"

Besides, you confused me with the description. You are checking $f to decide if you add an extra SP in front of $p but what comes in the end result is "$f$r$p", so "between the branch and marker" is not even true. Also why is $r ignored while deciding if you need this extra SP in the first place?

I also happen to think that the user should not even be worried about the divergence with the upstream when the repository is in any of the special states, in which case $r is not empty (e.g. "|REBASE-i"). So the above part may become:

	local f="$w$i$s$u"
	printf "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}${p:-$r}"
But that would be a separate topic.
Previous: Todd Zullinger
Message 2 of 2 in “completion: Add space to PS1 when showing upstream”
  1. completion: Add space to PS1 when showing upstreamTodd Zullinger, Mar 18, 2011
  2. Junio C HamanoMar 18, 2011

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.