From 6be8b0b2737a1fbfed2e409c88cc804e6fc5bdf3 Mon Sep 17 00:00:00 2001 From: Miguel Duarte Date: Mon, 22 Apr 2013 11:06:19 +0100 Subject: [PATCH] Fetch new remote revisions every other GIT_PROMPT_FETCH_TIMEOUT minutes (5 is the default) --- gitprompt.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/gitprompt.sh b/gitprompt.sh index 84791fa..ec63263 100644 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -7,6 +7,9 @@ fi # Reset ResetColor="\[\033[0m\]" # Text Reset +# fetch remote revisions every other $GIT_PROMPT_FETCH_TIMEOUT (default 5) minutes +GIT_PROMPT_FETCH_TIMEOUT=${1-5} + # Regular Colors Red="\[\033[0;31m\]" # Red Yellow="\[\033[0;33m\]" # Yellow @@ -61,6 +64,18 @@ function update_current_git_vars() { } function setGitPrompt() { + repo=`git rev-parse --show-toplevel 2> /dev/null` + if [[ ! -e $repo ]]; then + PS1="$PROMPT_START$PROMPT_END" + return + fi + + FETCH_HEAD=$repo/.git/FETCH_HEAD + # Fech repo if local is stale for more than $GIT_FETCH_TIMEOUT minutes + if [[ ! -e $FETCH_HEAD || -e `find $FETCH_HEAD -mmin +$GIT_PROMPT_FETCH_TIMEOUT` ]] + then + git fetch --quiet + fi update_current_git_vars set_virtualenv