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

Re: [PATCH] git-prompt: preserve command exit status

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 22, 2014, 17:19 UTC
Message-ID
<xmqqa92fbo0j.fsf@gitster.dls.corp.google.com>
In-Reply-To
<alpine.LSU.2.00.1412221429490.28934@hermes-1.csi.cam.ac.uk>
Tony Finch <dot@dotat.at> writes:
Show 25 quoted lines
> Signed-off-by: Tony Finch <dot@dotat.at>
> ---
>  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 c5473dc..5fe69d0 100644
> --- a/contrib/completion/git-prompt.sh
> +++ b/contrib/completion/git-prompt.sh
> @@ -288,6 +288,7 @@ __git_eread ()
>  # In this mode you can request colored hints using GIT_PS1_SHOWCOLORHINTS=true
>  __git_ps1 ()
>  {
> +	local exit=$?
>  	local pcmode=no
>  	local detached=no
>  	local ps1pc_start='\u@\h:\w '
> @@ -511,4 +512,7 @@ __git_ps1 ()
>  	else
>  		printf -- "$printf_format" "$gitstring"
>  	fi
> +
> +	# preserve exit status
> +	return $exit
>  }

Hmmmm. I thought "The patch trivially makes sense! Why didn't anybody notice this before?!?", but then noticed that I never suffered from an obvious consequence from the current lack of the exit-code-preserving:

    : gitster git.git/master; echo "<$PS1>"
    <: \h \W$(__git_ps1 "/%s"); >
    : gitster git.git/master; false
    : gitster git.git/master; echo $?
    1

And it does not seem that it is needed, at least for my use pattern:

    : gitster git.git/master; ps1func () { echo "What Now: "; exit 8; }
    : gitster git.git/master; PS1='$(ps1func)'
    What Now: echo $?
    0
    What Now: (exit 6)
    What Now: echo $?
    6

Also it does not seem that it is needed for the other style to use PROMPT_COMMAND:

    : gitster git.git/master; sh
    $ . contrib/completion/git-prompt.sh
    $ PROMPT_COMMAND='__git_ps1 "\h \W" "; "'
    gitster git.git (master); (exit 13)
    gitster git.git (master); echo $?
    13
    gitster git.git (master); true
    gitster git.git (master); echo $?
    0

So, what are you fixing? In other words, please describe how it fails in the log message.

Puzzled...
Previous: Tony FinchNext: Tony Finch
Message 2 of 9 in “git-prompt: preserve command exit status”
  1. git-prompt: preserve command exit statusTony Finch, Dec 22, 2014
  2. Junio C HamanoDec 22, 2014
  3. git-prompt: preserve value of $? inside shell promptTony Finch, Dec 22, 2014
  4. Junio C HamanoDec 22, 2014
  5. Tony FinchDec 22, 2014
  6. SZEDER GáborJan 13, 2015
  7. Tony FinchJan 14, 2015
  8. git-prompt: preserve value of $? in all casesTony Finch, Jan 14, 2015
  9. SZEDER GáborJan 14, 2015

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.