zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH 2/2] Add Git hook comparing local HEAD to remote HEAD to vcs_info-examples
@ 2010-07-15 22:34 Seth House
  2010-07-19 19:07 ` Frank Terbeck
  0 siblings, 1 reply; 2+ messages in thread
From: Seth House @ 2010-07-15 22:34 UTC (permalink / raw)
  To: zsh-workers

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



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH 2/2] Add Git hook comparing local HEAD to remote HEAD to vcs_info-examples
  2010-07-15 22:34 [PATCH 2/2] Add Git hook comparing local HEAD to remote HEAD to vcs_info-examples Seth House
@ 2010-07-19 19:07 ` Frank Terbeck
  0 siblings, 0 replies; 2+ messages in thread
From: Frank Terbeck @ 2010-07-19 19:07 UTC (permalink / raw)
  To: Seth House; +Cc: zsh-workers

Seth House wrote:
> This is the Git version of the existing Mercurial example that shows a
> marker comparing your local branch status to a remote branch.

Hey!

This one didn't apply, because your client wrapped two long lines.

[...]
> +    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)
[...]


I fixed that up manually. Since you used `git' anyway to produce the
patches, use `git send-email' to send the patches, too. That tool will
not screw up patches, like some MUAs (especially webmail clients) do.

Regards, Frank


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-07-19 19:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-15 22:34 [PATCH 2/2] Add Git hook comparing local HEAD to remote HEAD to vcs_info-examples Seth House
2010-07-19 19:07 ` Frank Terbeck

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).