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
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
May 4, 2017, 09:16 UTC
Message-ID
<CACBZZX6XdwND2-7cY0zp8+K_uh60tn-i_r9V7HAe2X-a-RJeQA@mail.gmail.com>
In-Reply-To
<c8879806-4e43-d033-bd69-918e730e2d05@hale.ee>
On Thu, May 4, 2017 at 10:26 AM, Tom Hale <tom@hale.ee> wrote:
Show 21 quoted lines
>
> On 17/04/17 11:24, Junio C Hamano wrote:
>> "Tom \"Ravi\" Hale" <tom@hale.ee> 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.
>> >
>> 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 || :)"
>
> Nope, that would cause the next line
>     rev_parse_exit_code="$?"
> to always be assigned 0.
>
> I believe the patch we're after is attached.

I see how this would fix things, but this just seems like a rather crazy thing for us to support, we can take this patch, but it's going to take quite some maintenance burden to ensure that this code is set -e clean going forward, and I don't think we should take a patch like this without some general support in the regression tests to ensure that the completion code is set -e clean, otherwise this is going to very easily regress the next time someone not aware of this patches it.

What's the real use-case here? If you do "set -e" in your shell you also get e.g.:

    $ ls -l blah
    ls: cannot access blah: No such file or directory
    === Command terminated with exit status 2 (Thu May  4 11:16:03 2017) ===

I.e. any little failure will terminate your shell, are you actually running a shell like this? For what purpose?

Previous: Tom HaleNext: Tom Hale
Message 4 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.