From 22cf85c0f8d405cf0e73a6362e6c28c5c1121fab Mon Sep 17 00:00:00 2001 From: Philip Hofstetter Date: Wed, 28 Dec 2011 14:59:55 +0100 Subject: [PATCH 1/3] add function to determine current upstream for git_prompt_ahead() (in lib/git.zsh) to work with remotes different than 'origin', we need a way to determine the origin of the currently active branch. This uses git-config to find the current branches remote (if any) --- plugins/git/git.plugin.zsh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index c1b382b2c..bf6233c5d 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -52,6 +52,11 @@ function current_branch() { echo ${ref#refs/heads/} } +function git_current_upstream(){ + local upstream=$(git config --get branch."$(current_branch)".remote) || return + echo $upstream +} + # these aliases take advantage of the previous function alias ggpull='git pull origin $(current_branch)' compdef ggpull=git From 8217193b73a32398a7538b9c0bb004ff23ea2222 Mon Sep 17 00:00:00 2001 From: Philip Hofstetter Date: Wed, 28 Dec 2011 15:02:11 +0100 Subject: [PATCH 2/3] don't assume "origin" in git_prompt_ahead() it's possible that you are working on a tracking branch that tracks something else than origin. This uses the new git_current_upstream() function to determine the remote of the branch that is currently being tracked --- lib/git.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/git.zsh b/lib/git.zsh index defa062c6..805345663 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -15,7 +15,7 @@ parse_git_dirty() { # Checks if there are commits ahead from remote function git_prompt_ahead() { - if $(echo "$(git log origin/$(current_branch)..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then + if $(echo "$(git log $(git_current_upstream)/$(current_branch)..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then echo "$ZSH_THEME_GIT_PROMPT_AHEAD" fi } From e2def7f1f3d6a23ac79e46df05af4db28211c4ce Mon Sep 17 00:00:00 2001 From: Philip Hofstetter Date: Wed, 28 Dec 2011 15:03:23 +0100 Subject: [PATCH 3/3] use git_prompt_ahead in git_prompt_info now that git_prompt_ahead() works more consistenly and doesn't insist on the remote being called 'origin', we can actually include git_prompt_ahead() in the default prompt. git_prompt_ahead() makes use of ZSH_THEME_GIT_PROMPT_AHEAD which is currently unused, but can now be used to show if your branch is ahead of the one you are tracking --- lib/git.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/git.zsh b/lib/git.zsh index 805345663..14fba2be5 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -1,7 +1,7 @@ # get the name of the branch we are on function git_prompt_info() { ref=$(git symbolic-ref HEAD 2> /dev/null) || return - echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX" + echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$(git_prompt_ahead)$ZSH_THEME_GIT_PROMPT_SUFFIX" } # Checks if working tree is dirty