Bug 25990 - ZSH's PS1 in Bash when running bash from zsh with git installed
Summary: ZSH's PS1 in Bash when running bash from zsh with git installed
Status: RESOLVED FIXED
Alias: None
Product: Mageia
Classification: Unclassified
Component: RPM Packages (show other bugs)
Version: 7
Hardware: All Linux
Priority: Normal minor
Target Milestone: ---
Assignee: QA Team
QA Contact:
URL:
Whiteboard: MGA7-64-OK
Keywords: advisory, validated_update
Depends on:
Blocks:
 
Reported: 2019-12-29 14:29 CET by Alex Kerzner
Modified: 2020-01-05 16:39 CET (History)
4 users (show)

See Also:
Source RPM: git
CVE:
Status comment:


Attachments

Description Alex Kerzner 2019-12-29 14:29:26 CET
Description of problem:

If zsh, bash, and git (and git's dependencies, as it might be git-prompt doing it) installed, you can demonstrate the following:

```
user@hostname ~ % bash
%B%F{red}%(?..%? )%f%b%B%F{blue}%n%f%b@%m %B%40<..<%~%<< %b%#
```

Without git installed:

```
user@hostname ~ % bash
[user@hostname ~]$
```


Version-Release number of selected component (if applicable):

git-email-2.21.1-1.mga7
git-svn-2.21.1-1.mga7
git-prompt-2.21.1-1.mga7
git-core-2.21.1-1.mga7
git-arch-2.21.1-1.mga7
git-core-oldies-2.21.1-1.mga7
git-2.21.1-1.mga7
git-cvs-2.21.1-1.mga7
gitk-2.21.1-1.mga7
zsh-5.7.1-1.mga7
bash-completion-2.8-2.mga7
bash-4.4-23.1.mga7

How reproducible:

Consistent.


Steps to Reproduce:
1. Install `zsh`, `git`; requires `bash`, so hope you have that one too.
2. Change shell to /bin/zsh: `chsh --shell /bin/zsh <user>`
3. Login with new shell (e.g. with ssh or a new console)
4. Run: `bash`


Notes:

* I don't think PS1 should be marked for export.
* Workaround: `typeset +x PS1`
* There may be additional variables that have similar undesirable effects.
* Top suspects: git-prompt, zsh, bash
Comment 1 David Walser 2019-12-29 18:31:13 CET
The only place I can find PS1 being exported is in /etc/profile (from the setup package).  If you remove PS1 from the export list in /etc/profile, do you still see this issue?
Comment 2 David Walser 2019-12-29 18:32:28 CET
CC'ing two packagers who have expertise in the involved packages.

CC: (none) => shlomif, smelror

Comment 3 Alex Kerzner 2019-12-29 19:47:39 CET
I removed it from /etc/profile, but it didn't go away. I also fully and properly ruled out grml-zsh-config - I thought I had ruled it out before, but now I know I was wrong.


With grml-zsh-config completely out of the equation, the prompt becomes '%n@%m %3~ %(!.#.$)'. 

Searching again, I found this:

```
/etc/profile.d/93git-branch.sh:  export PS1="$(echo -n "$PS1" | sed "s|\\\W\]|\\\W\$(type __git_ps1 >/dev/null  2>\&1 \&\& __git_ps1 \" (%s)\")\]|")"
```

This is in an if-statement that sources `/usr/share/doc/git-core/contrib/completion/git-prompt.sh` if it exists.
Comment 4 Lewis Smith 2019-12-29 21:33:09 CET
Thanks to both of you for the detective work.
In the light of comment 3, this looks definitely down to git; so assigning to (rather than CC) Shlomi.

CC: shlomif => (none)
Assignee: bugsquad => shlomif

Comment 5 David Walser 2019-12-29 21:54:37 CET
Ahh yeah I searched the git sources but didn't see the local SOURCES/93git-branch.sh in our package.

Source RPM: (none) => git

Comment 6 Stig-Ørjan Smelror 2019-12-29 22:41:41 CET
The solution is to remove "export" from /etc/profile.d/93git-branch.sh

Update pushed to Mageia 7 and Cauldron.
Comment 7 Stig-Ørjan Smelror 2019-12-29 22:51:15 CET
Advisory
========

An error in /etc/profile.d/93git-brach.sh made the bash prompt garbled.

References
==========
https://bugs.mageia.org/show_bug.cgi?id=25990

Files
=====

Uploaded to core/updates_testing

git-2.21.1-1.1.mga7
git-core-2.21.1-1.1.mga7
gitk-2.21.1-1.1.mga7
lib64git-devel-2.21.1-1.1.mga7
git-subtree-2.21.1-1.1.mga7
git-svn-2.21.1-1.1.mga7
git-cvs-2.21.1-1.1.mga7
git-arch-2.21.1-1.1.mga7
git-email-2.21.1-1.1.mga7
perl-Git-2.21.1-1.1.mga7
perl-Git-SVN-2.21.1-1.1.mga7
git-core-oldies-2.21.1-1.1.mga7
gitweb-2.21.1-1.1.mga7
git-prompt-2.21.1-1.1.mga7

from git-2.21.1-1.1.mga7.src.rpm

Assignee: shlomif => qa-bugs

Comment 8 David Walser 2019-12-30 00:10:17 CET
Alex, let us know if this update solves the issue.

Note to whoever commits the advisory to SVN to beware the typo.
Comment 9 Alex Kerzner 2019-12-30 00:44:56 CET
Removing `export` from `/etc/profile.d/93git-branch.sh` worked. I'll let you know when I test the updated package.
Comment 10 Alex Kerzner 2020-01-01 13:50:09 CET
Tested the packages from the testing repo. It works as expected now - which is to say it doesn't interfere.

However, further testing shows that it does not have an effect on initial login. This other problem is most likely outside the scope of this bug, and may also be expected behavior.


The behavior is different between login shells and non-login shells.

Non-login shells:
1. /etc/bashrc is loaded first, setting PS1 appropriately
2. /etc/profile.d/* are loaded
3. When `/etc/profile.d/93git-branch.sh` is loaded, PS1 is appropriately set.
4. We have PS1 with git branch information.

Login shells:
1. /etc/profile is loaded first, loading /etc/profile.d/* .
2. When `/etc/profile.d/93git-branch.sh` is loaded, PS1 is '\s-\v\$' - the default. Because it hasn't been properly set yet, the sed command doesn't see '\W' and has no effect.
3. /etc/bashrc is loaded (via `~/.bash_profile`), setting PS1 appropriately.
4. We have PS1 withOUT git branch information.


Not sure if that is desirable or intended. Regardless, if you want it to work in login shells, either modify PS1 in /etc/profile.d (but only if it exists... and even then, I won't pretend I know all of the side effects), or move the sed to /etc/bashrc (which also brings its own problems). Sourcing `/etc/profile.d/93git-branch.sh` in my .bashrc should work, too.

I think this other issue should be its own ticket, so let me know if I should make one.
Comment 11 Alex Kerzner 2020-01-01 13:51:52 CET
To be clear, the original problem has now been resolved.
David Walser 2020-01-01 22:51:55 CET

Whiteboard: (none) => MGA7-64-OK

Comment 12 Thomas Andrews 2020-01-03 20:04:47 CET
Validating, then. Advisory in Comment 7.

Keywords: (none) => validated_update
CC: (none) => andrewsfarm, sysadmin-bugs

Thomas Backlund 2020-01-05 15:32:47 CET

CC: (none) => tmb
Keywords: (none) => advisory

Comment 13 Mageia Robot 2020-01-05 16:39:30 CET
An update for this issue has been pushed to the Mageia Updates repository.

https://advisories.mageia.org/MGAA-2020-0006.html

Status: NEW => RESOLVED
Resolution: (none) => FIXED


Note You need to log in before you can comment on or make changes to this bug.