Merge pull request #93 from DenJohX/master

FIX #92 GIT_PROMPT_ONLY_IN_REPO=1 should honor whatever previus prompt was
master
Martin Gondermann 11 years ago
commit e1b34607a8
  1. 32
      gitprompt.sh

@ -279,13 +279,37 @@ function setLastCommandState() {
GIT_PROMPT_LAST_COMMAND_STATE=$? GIT_PROMPT_LAST_COMMAND_STATE=$?
} }
function we_are_on_repo() {
if [[ -e "$(git rev-parse --git-dir 2> /dev/null)" ]]; then
echo 1
fi
echo 0
}
function update_old_git_prompt() {
local in_repo=$(we_are_on_repo)
if [[ $GIT_PROMPT_OLD_DIR_WAS_GIT = 0 ]]; then
OLD_GITPROMPT=$PS1
fi
GIT_PROMPT_OLD_DIR_WAS_GIT=$in_repo
}
function setGitPrompt() { function setGitPrompt() {
update_old_git_prompt
local repo=`git rev-parse --show-toplevel 2> /dev/null`
if [[ ! -e "$repo" ]] && [[ "$GIT_PROMPT_ONLY_IN_REPO" = 1 ]]; then
# we do not permit bash-git-prompt outside git repos, so nothing to do
PS1="$OLD_GITPROMPT"
return
fi
local EMPTY_PROMPT local EMPTY_PROMPT
local __GIT_STATUS_CMD local __GIT_STATUS_CMD
git_prompt_config git_prompt_config
local repo=`git rev-parse --show-toplevel 2> /dev/null`
if [[ ! -e "$repo" ]]; then if [[ ! -e "$repo" ]]; then
PS1="$EMPTY_PROMPT" PS1="$EMPTY_PROMPT"
return return
@ -440,10 +464,14 @@ function gp_install_prompt {
else else
prompt_callback="prompt_callback_default" prompt_callback="prompt_callback_default"
fi fi
if [ -z "$OLD_GITPROMPT" ]; then if [ -z "$OLD_GITPROMPT" ]; then
OLD_GITPROMPT=$PS1 OLD_GITPROMPT=$PS1
fi fi
if [ -z "$GIT_PROMPT_OLD_DIR_WAS_GIT" ]; then
GIT_PROMPT_OLD_DIR_WAS_GIT=$(we_are_on_repo)
fi
if [ -z "$PROMPT_COMMAND" ]; then if [ -z "$PROMPT_COMMAND" ]; then
PROMPT_COMMAND=setGitPrompt PROMPT_COMMAND=setGitPrompt

Loading…
Cancel
Save