Re: [PATCH] __git_ps1: Don't kill shell if user types `set -e`

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Tom \"Ravi\" Hale" <tom@xxxxxxx> writes:

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



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]