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

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?

Previous: Tom "Ravi" HaleNext: Tom Hale
Message 2 of 5 in “__git_ps1: Don't kill shell if user types `set -e`”
  1. __git_ps1: Don't kill shell if user types `set -e`Tom "Ravi" Hale, Apr 16, 2017
  2. Junio C HamanoApr 17, 2017
  3. Tom HaleMay 4, 2017
  4. Ævar Arnfjörð BjarmasonMay 4, 2017
  5. Tom HaleMay 4, 2017

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.