From: "Tom \"Ravi\" Hale" <tom@hale.ee>
To: git <git@vger.kernel.org>
Subject: [PATCH] __git_ps1: Don't kill shell if user types `set -e`
Date: Sun, 16 Apr 2017 15:28:33 +0700 [thread overview]
Message-ID: <b344d0c3-c8b8-da27-79f6-ae750be6830a@hale.ee> (raw)
[-- Attachment #1: Type: text/plain, Size: 637 bytes --]
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)"
I couldn't write a test to illustrate this - the test harness seems to
be preventing
`set -e` from having an effect.
<attachment>
Signed-off-by: Tom "Ravi" Hale <tom@hale.ee>
[-- Attachment #2: 0001-__git_ps1-Don-t-kill-shell-if-user-types-set-e.patch --]
[-- Type: text/x-patch, Size: 1008 bytes --]
From 7867768f4516559c129ed9eb07ae29c36a6c9367 Mon Sep 17 00:00:00 2001
From: "Tom \"Ravi\" Hale" <tom@hale.ee>
Date: Sun, 16 Apr 2017 14:10:10 +0700
Subject: [PATCH] __git_ps1: Don't kill shell if user types `set -e`
Ensure that `set +e` is in effect inside __git_ps1 to prevent any commands
exiting non-zero from killing an interactive shell in which the user has run
`set -e`.
---
contrib/completion/git-prompt.sh | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 97eacd7..15a0b74 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -304,6 +304,10 @@ __git_ps1 ()
local ps1pc_start='\u@\h:\w '
local ps1pc_end='\$ '
local printf_format=' (%s)'
+ # Prevent any non-zero exit statuses from killing an interactive shell in the
+ # case that a user types `set -e`
+ local -- - # Shadow shell options in $- (restored upon return)
+ set +e
case "$#" in
2|3) pcmode=yes
--
2.11.1
next reply other threads:[~2017-04-16 8:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-16 8:28 Tom "Ravi" Hale [this message]
2017-04-17 4:24 ` [PATCH] __git_ps1: Don't kill shell if user types `set -e` Junio C Hamano
2017-05-04 8:26 ` Tom Hale
2017-05-04 9:16 ` Ævar Arnfjörð Bjarmason
2017-05-04 9:35 ` Tom Hale
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b344d0c3-c8b8-da27-79f6-ae750be6830a@hale.ee \
--to=tom@hale.ee \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).