summaryrefslogtreecommitdiff
path: root/lib/git.zsh
diff options
context:
space:
mode:
authorPeter Tillemans <pti@snamellit.com>2013-01-02 09:42:14 +0100
committerPeter Tillemans <pti@snamellit.com>2013-01-02 09:42:14 +0100
commit587832f15579398e54690e62ea588178e951f8f8 (patch)
tree1e2149e743710e2c72a567a042606333bbad88da /lib/git.zsh
parent55cc936d4e6d88f18518cedc9574b1df10702f8b (diff)
parent80a603259657acab97badbae20003b5a34c901f9 (diff)
downloadzsh-587832f15579398e54690e62ea588178e951f8f8.tar.gz
zsh-587832f15579398e54690e62ea588178e951f8f8.tar.bz2
zsh-587832f15579398e54690e62ea588178e951f8f8.zip
Merge branch 'master' of https://github.com/robbyrussell/oh-my-zsh
Diffstat (limited to 'lib/git.zsh')
-rw-r--r--lib/git.zsh40
1 files changed, 37 insertions, 3 deletions
diff --git a/lib/git.zsh b/lib/git.zsh
index fb4ad8ca6..b1dfce357 100644
--- a/lib/git.zsh
+++ b/lib/git.zsh
@@ -1,6 +1,7 @@
# get the name of the branch we are on
function git_prompt_info() {
- ref=$(git symbolic-ref HEAD 2> /dev/null) || return
+ ref=$(git symbolic-ref HEAD 2> /dev/null) || \
+ ref=$(git rev-parse --short HEAD 2> /dev/null) || return
echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX"
}
@@ -18,6 +19,25 @@ parse_git_dirty() {
fi
}
+# get the difference between the local and remote branches
+git_remote_status() {
+ remote=${$(git rev-parse --verify ${hook_com[branch]}@{upstream} --symbolic-full-name 2>/dev/null)/refs\/remotes\/}
+ if [[ -n ${remote} ]] ; then
+ ahead=$(git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l)
+ behind=$(git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc -l)
+
+ if [ $ahead -eq 0 ] && [ $behind -gt 0 ]
+ then
+ echo "$ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE"
+ elif [ $ahead -gt 0 ] && [ $behind -eq 0 ]
+ then
+ echo "$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE"
+ elif [ $ahead -gt 0 ] && [ $behind -gt 0 ]
+ then
+ echo "$ZSH_THEME_GIT_PROMPT_DIVERGED_REMOTE"
+ fi
+ fi
+}
# Checks if there are commits ahead from remote
function git_prompt_ahead() {
@@ -38,7 +58,7 @@ function git_prompt_long_sha() {
# Get the status of the working tree
git_prompt_status() {
- INDEX=$(git status --porcelain 2> /dev/null)
+ INDEX=$(git status --porcelain -b 2> /dev/null)
STATUS=""
if $(echo "$INDEX" | grep '^?? ' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_UNTRACKED$STATUS"
@@ -60,18 +80,32 @@ git_prompt_status() {
fi
if $(echo "$INDEX" | grep '^ D ' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS"
+ elif $(echo "$INDEX" | grep '^D ' &> /dev/null); then
+ STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS"
elif $(echo "$INDEX" | grep '^AD ' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS"
fi
+ if $(git rev-parse --verify refs/stash >/dev/null 2>&1); then
+ STATUS="$ZSH_THEME_GIT_PROMPT_STASHED$STATUS"
+ fi
if $(echo "$INDEX" | grep '^UU ' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_UNMERGED$STATUS"
fi
+ if $(echo "$INDEX" | grep '^## .*ahead' &> /dev/null); then
+ STATUS="$ZSH_THEME_GIT_PROMPT_AHEAD$STATUS"
+ fi
+ if $(echo "$INDEX" | grep '^## .*behind' &> /dev/null); then
+ STATUS="$ZSH_THEME_GIT_PROMPT_BEHIND$STATUS"
+ fi
+ if $(echo "$INDEX" | grep '^## .*diverged' &> /dev/null); then
+ STATUS="$ZSH_THEME_GIT_PROMPT_DIVERGED$STATUS"
+ fi
echo $STATUS
}
#compare the provided version of git to the version installed and on path
#prints 1 if input version <= installed version
-#prints -1 otherwise
+#prints -1 otherwise
function git_compare_version() {
local INPUT_GIT_VERSION=$1;
local INSTALLED_GIT_VERSION