Code

[PATCH] Fixed/Extended example for update hook
authorJosef Weidendorfer <Josef.Weidendorfer@gmx.de>
Sat, 13 Aug 2005 20:39:41 +0000 (22:39 +0200)
committerJunio C Hamano <junkio@cox.net>
Mon, 15 Aug 2005 10:00:21 +0000 (03:00 -0700)
Add sample code to distinguish --force rebased head and simple
fast-forward.  At the same time fixes a real bug; the "new ref"
path was using a wrong parameter.

Signed-off-by: Junio C Hamano <junkio@cox.net>
templates/hooks--update

index 540ade0d52c84d59bbdd863f60a0e90203643ff2..0726975367de1bff2d4575537f89f52ff87fa1a7 100644 (file)
@@ -1,6 +1,7 @@
 #!/bin/sh
 #
 # An example hook script to mail out commit update information.
+# Called by git-receive-pack with arguments: refname sha1-old sha1-new
 #
 # To enable this hook:
 # (1) change the recipient e-mail address
@@ -12,10 +13,15 @@ recipient="commit-list@mydomain.xz"
 if expr "$2" : '0*$' >/dev/null
 then
        echo "Created a new ref, with the following commits:"
-       git-rev-list --pretty "$2"
+       git-rev-list --pretty "$3"
 else
-       echo "New commits:"
-       git-rev-list --pretty "$3" "^$2"
+       $base=$(git-merge-base "$2" "$3")
+       if [ $base == "$2" ]; then
+               echo "New commits:"
+       else
+               echo "Rebased ref, commits from common ancestor:"
+fi
+git-rev-list --pretty "$3" "^$base"
 fi |
 mail -s "Changes to ref $1" "$recipient"
 exit 0