Skip to content

Commit

Permalink
Merge branch 'tf/prompt-preserve-exit-status'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Junio C Hamano committed Jan 14, 2015
2 parents e1ef7d1 + 6babe76 commit 9920c71
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions contrib/completion/git-prompt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,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
Expand All @@ -312,7 +313,7 @@ __git_ps1 ()
;;
0|1) printf_format="${1:-$printf_format}"
;;
*) return
*) return $exit
;;
esac

Expand Down Expand Up @@ -360,7 +361,7 @@ __git_ps1 ()
rev_parse_exit_code="$?"

if [ -z "$repo_info" ]; then
return
return $exit
fi

local short_sha
Expand All @@ -380,7 +381,7 @@ __git_ps1 ()
[ "$(git config --bool bash.hideIfPwdIgnored)" != "false" ] &&
git check-ignore -q .
then
return
return $exit
fi

local r=""
Expand Down Expand Up @@ -426,7 +427,7 @@ __git_ps1 ()
else
local head=""
if ! __git_eread "$g/HEAD" head; then
return
return $exit
fi
# is it a symbolic ref?
b="${head#ref: }"
Expand Down Expand Up @@ -523,6 +524,5 @@ __git_ps1 ()
printf -- "$printf_format" "$gitstring"
fi

# preserve exit status
return $exit
}

0 comments on commit 9920c71

Please sign in to comment.