Skip to content

Commit

Permalink
Merge pull request #93 from DenJohX/master
Browse files Browse the repository at this point in the history
FIX #92 GIT_PROMPT_ONLY_IN_REPO=1 should honor whatever previus prompt was
  • Loading branch information
magicmonty committed Oct 19, 2014
2 parents 5496b4c + 222a49b commit e1b3460
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions gitprompt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,37 @@ function setLastCommandState() {
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() {
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 __GIT_STATUS_CMD

git_prompt_config

local repo=`git rev-parse --show-toplevel 2> /dev/null`
if [[ ! -e "$repo" ]]; then
PS1="$EMPTY_PROMPT"
return
Expand Down Expand Up @@ -440,10 +464,14 @@ function gp_install_prompt {
else
prompt_callback="prompt_callback_default"
fi

if [ -z "$OLD_GITPROMPT" ]; then
OLD_GITPROMPT=$PS1
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
PROMPT_COMMAND=setGitPrompt
Expand Down

0 comments on commit e1b3460

Please sign in to comment.