Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH 2/2] Add Git hook comparing local HEAD to remote HEAD to vcs_info-examples



This is the Git version of the existing Mercurial example that shows a
marker comparing your local branch status to a remote branch.
---
 Misc/vcs_info-examples |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/Misc/vcs_info-examples b/Misc/vcs_info-examples
index 1c15972..b769906 100644
--- a/Misc/vcs_info-examples
+++ b/Misc/vcs_info-examples
@@ -155,6 +155,29 @@ function +vi-hg-shorthash() {
     ret=1
 }
 
+
+### Compare local changes to remote changes
+
+### git: Show +N/-N when your local branch is ahead-of or behind remote HEAD.
+# Make sure you have added misc to your 'formats':  %m
+zstyle ':vcs_info:git*+set-message:*' hooks git-st
+function +vi-git-st() {
+    local ahead behind
+    local -a gitstatus
+
+    # for git prior to 1.7
+    # ahead=$(git rev-list origin/${hook_com[branch]}..HEAD | wc -l)
+    ahead=$(git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc 
-l)
+    (( $ahead )) && gitstatus+=( "+${ahead}" )
+
+    # for git prior to 1.7
+    # behind=$(git rev-list HEAD..origin/${hook_com[branch]} | wc -l)
+    behind=$(git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc 
-l)
+    (( $behind )) && gitstatus+=( "-${behind}" )
+
+    hook_com[misc]+=${(j:/:)gitstatus}
+}
+
 ### hg: Show marker when the working directory is not on a branch head
 # This may indicate that running `hg up` will do something
 # NOTE: the branchheads.cache file is not updated with every Mercurial
-- 
1.7.1.1




Messages sorted by: Reverse Date, Date, Thread, Author