git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Tom Hale <tom@hale.ee>
To: Junio C Hamano <gitster@pobox.com>
Cc: git <git@vger.kernel.org>
Subject: Re: [PATCH] __git_ps1: Don't kill shell if user types `set -e`
Date: Thu, 4 May 2017 15:26:58 +0700	[thread overview]
Message-ID: <c8879806-4e43-d033-bd69-918e730e2d05@hale.ee> (raw)
In-Reply-To: <xmqq60i3k6ed.fsf@gitster.mtv.corp.google.com>

[-- Attachment #1: Type: text/plain, Size: 690 bytes --]


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.

-- 
Cheers,

Tom

[-- Attachment #2: 0001-Prevent-non-zero-exit-if-outside-a-repository.patch --]
[-- Type: text/x-patch, Size: 888 bytes --]

From 74fa2e2fa058f89605cf0b2774ad8e9df981cf86 Mon Sep 17 00:00:00 2001
From: "Tom \"Ravi\" Hale" <tom@hale.ee>
Date: Sun, 16 Apr 2017 14:15:14 +0700
Subject: [PATCH] Prevent non-zero exit if outside a repository

---
 contrib/completion/git-prompt.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 97eacd7..d0d890c 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -361,8 +361,8 @@ __git_ps1 ()
 	local repo_info rev_parse_exit_code
 	repo_info="$(git rev-parse --git-dir --is-inside-git-dir \
 		--is-bare-repository --is-inside-work-tree \
-		--short HEAD 2>/dev/null)"
-	rev_parse_exit_code="$?"
+		--short HEAD 2>/dev/null)" && 
+		rev_parse_exit_code="$?" || : # Don't die if "set -e"
 
 	if [ -z "$repo_info" ]; then
 		return $exit
-- 
2.12.2


  reply	other threads:[~2017-05-04  8:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-16  8:28 [PATCH] __git_ps1: Don't kill shell if user types `set -e` Tom "Ravi" Hale
2017-04-17  4:24 ` Junio C Hamano
2017-05-04  8:26   ` Tom Hale [this message]
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=c8879806-4e43-d033-bd69-918e730e2d05@hale.ee \
    --to=tom@hale.ee \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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).