Re: [PATCH] __git_ps1: Don't kill shell if user types `set -e`
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Apr 17, 2017, 04:24 UTC
- Message-ID
- <xmqq60i3k6ed.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <b344d0c3-c8b8-da27-79f6-ae750be6830a@hale.ee>
"Tom \"Ravi\" Hale" <tom@hale.ee> writes:
Show 12 quoted lines
> If a user types `set -e` in an interactive shell, and is using __git_ps1 > to set > their prompt, the shell will die if the current directory isn't inside a git > repository. > > This is because `set -e` instructs the shell to exit upon a command > returning a non-zero exit status, and the following command exits with > status 128: > > repo_info="$(git rev-parse --git-dir --is-inside-git-dir \ > --is-bare-repository --is-inside-work-tree \ > --short HEAD 2>/dev/null)"
Hmph. So the fix would be something like this?
repo_info="$(git rev-parse --git-dir --is-inside-git-dir \ --is-bare-repository --is-inside-work-tree \ - --short HEAD 2>/dev/null)" + --short HEAD 2>/dev/null || :)"
I am too afraid to ask what a user would try to achieve by doing the "set -e" thing in an interactive session. It is understandable (I am not saying I think it is necessarily a good idea) to do so in a script, but for an interactive shell?