From: Junio C Hamano Date: Wed, 14 Jan 2015 20:35:48 +0000 (-0800) Subject: Merge branch 'tf/prompt-preserve-exit-status' X-Git-Tag: v2.3.0-rc1~14 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/9920c718254d946e685ef1295ff9ea0c14bac9cf?ds=inline;hp=-c Merge branch 'tf/prompt-preserve-exit-status' Using the exit status of the last command in the prompt, e.g. PS1='$(__git_ps1) $? ', did not work well because the helper function stomped on the exit status. * tf/prompt-preserve-exit-status: git-prompt: preserve value of $? in all cases --- 9920c718254d946e685ef1295ff9ea0c14bac9cf diff --combined contrib/completion/git-prompt.sh index c0f62b54d4,3a11f4e97d..214e859f99 --- a/contrib/completion/git-prompt.sh +++ b/contrib/completion/git-prompt.sh @@@ -84,11 -84,6 +84,11 @@@ # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on # the colored output of "git status -sb" and are available only when # using __git_ps1 for PROMPT_COMMAND or precmd. +# +# If you would like __git_ps1 to do nothing in the case when the current +# directory is set up to be ignored by git, then set +# GIT_PS1_HIDE_IF_PWD_IGNORED to a nonempty value. Override this on the +# repository level by setting bash.hideIfPwdIgnored to "false". # check whether printf supports -v __git_printf_supports_v= @@@ -275,7 -270,7 +275,7 @@@ __git_ps1_colorize_gitstring ( __git_eread () { - f="$1" + local f="$1" shift test -r "$f" && read "$@" <"$f" } @@@ -293,6 -288,7 +293,7 @@@ # 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 @@@ -305,14 -301,10 +306,14 @@@ ps1pc_start="$1" ps1pc_end="$2" printf_format="${3:-$printf_format}" + # set PS1 to a plain prompt so that we can + # simply return early if the prompt should not + # be decorated + PS1="$ps1pc_start$ps1pc_end" ;; 0|1) printf_format="${1:-$printf_format}" ;; - *) return + *) return $exit ;; esac @@@ -360,7 -352,11 +361,7 @@@ rev_parse_exit_code="$?" if [ -z "$repo_info" ]; then - return - if [ $pcmode = yes ]; then - #In PC mode PS1 always needs to be set - PS1="$ps1pc_start$ps1pc_end" - fi + return $exit fi local short_sha @@@ -375,14 -371,6 +376,14 @@@ local inside_gitdir="${repo_info##*$'\n'}" local g="${repo_info%$'\n'*}" + if [ "true" = "$inside_worktree" ] && + [ -n "${GIT_PS1_HIDE_IF_PWD_IGNORED-}" ] && + [ "$(git config --bool bash.hideIfPwdIgnored)" != "false" ] && + git check-ignore -q . + then - return ++ return $exit + fi + local r="" local b="" local step="" @@@ -426,7 -414,10 +427,7 @@@ else local head="" if ! __git_eread "$g/HEAD" head; then - return - if [ $pcmode = yes ]; then - PS1="$ps1pc_start$ps1pc_end" - fi + return $exit fi # is it a symbolic ref? b="${head#ref: }" @@@ -523,6 -514,5 +524,5 @@@ printf -- "$printf_format" "$gitstring" fi - # preserve exit status return $exit }