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

Re: [PATCH] git-prompt: preserve value of $? in all cases

From
SZEDER Gábor <szeder@ira.uka.de>
Date
Jan 14, 2015, 12:10 UTC
Message-ID
<20150114131006.Horde._hnEBDLPm_RUjO-IJlS9dw1@webmail.informatik.kit.edu>
In-Reply-To
<alpine.LSU.2.00.1501141005560.23307@hermes-1.csi.cam.ac.uk>
Hi,
Quoting Tony Finch <dot@dotat.at>:
Show 55 quoted lines
> Signed-off-by: Tony Finch <dot@dotat.at>
> ---
>  contrib/completion/git-prompt.sh | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/contrib/completion/git-prompt.sh  
> b/contrib/completion/git-prompt.sh
> index 3c3fc6d..3e70e74 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 ()
>  {
> +	# preserve exit status
>  	local exit=$?
>  	local pcmode=no
>  	local detached=no
> @@ -303,7 +304,7 @@ __git_ps1 ()
>  		;;
>  		0|1)	printf_format="${1:-$printf_format}"
>  		;;
> -		*)	return
> +		*)	return $exit
>  		;;
>  	esac
>
> @@ -355,7 +356,7 @@ __git_ps1 ()
>  			#In PC mode PS1 always needs to be set
>  			PS1="$ps1pc_start$ps1pc_end"
>  		fi
> -		return
> +		return $exit
>  	fi
>
>  	local short_sha
> @@ -416,7 +417,7 @@ __git_ps1 ()
>  				if [ $pcmode = yes ]; then
>  					PS1="$ps1pc_start$ps1pc_end"
>  				fi
> -				return
> +				return $exit
>  			fi
>  			# is it a symbolic ref?
>  			b="${head#ref: }"
> @@ -513,6 +514,5 @@ __git_ps1 ()
>  		printf -- "$printf_format" "$gitstring"
>  	fi
>
> -	# preserve exit status
>  	return $exit
>  }
> --
> 2.2.1.68.g56d9796

Thanks for the quick turnaround, looks good to me. I didn't remember the early return in the second hunk.

I wonder whether we could test this behavior... but how could we set $? and pass it to __git_ps1()?

Junio, as far as I can judge from the last What's cooking and the relevant patch emails on Gmane, this patch will have a textual conflict with the first patch in 'rh/hide-prompt-in-ignored-directory'. While the conflict is trivial (maybe git would even be able to resolve it by itself?), the second patch in that series adds yet another early return to __git_ps1(). Please be sure to add 'return $exit' when merging.

Best, Gábor

Previous: Tony Finch
Message 9 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.