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

2 messages from 2011-03-18 to 2011-03-18. Participants: Todd Zullinger, Junio C Hamano.
Thread: https://gitlist.dev/t/26773

## Todd Zullinger, 2011-03-18 15:02

Subject: [PATCH] completion: Add space to PS1 when showing upstream
Message-ID: <20110318150222.GB26236@inocybe.localdomain>
URL: https://gitlist.dev/e/20110318150222.GB26236%40inocybe.localdomain

```
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.  Add this space as needed so the branch name and upstream state
aren't confusingly mixed.

Signed-off-by: Todd Zullinger <tmz@pobox.com>
---
 contrib/completion/git-completion.bash |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

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 ()
 		fi
 
 		local f="$w$i$s$u"
+		[[ -z $f ]] && p="${p:+ $p}"
 		printf "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r$p"
 	fi
 }
-- 
1.7.4.1

-- 
Todd        OpenPGP -> KeyID: 0xBEAF0CE3 | URL: www.pobox.com/~tmz/pgp
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Giving money and power to government is like giving whiskey and car
keys to teenage boys.
    -- P.J. O'Rourke

```

## Junio C Hamano, 2011-03-18 20:01

Subject: Re: [PATCH] completion: Add space to PS1 when showing upstream
Message-ID: <7vtyf0w63k.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vtyf0w63k.fsf%40alter.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?

> 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.

```
