]> snippets.scripts.mit.edu Git - Scripts/git/.git/blob - git-hooks/zephyr-post-receive
zephyr-post-receive: Respect zephyr.instance on new branch creation.
[Scripts/git/.git] / git-hooks / zephyr-post-receive
1 #!/bin/sh
2 #
3 # This script is run after receive-pack has accepted a pack and the
4 # repository has been updated.  It is passed arguments in through stdin
5 # in the form
6 #  <oldrev> <newrev> <refname>
7 # For example:
8 #  aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master
9
10 class=`git config zephyr.class`
11 instance=`git config zephyr.instance`
12 zsig=`git config zephyr.zsig`
13 color=`git config --bool zephyr.color`
14
15 if [ "${color:-true}" = "true" ]; then
16     usecolor="--color"
17 else
18     usecolor=""
19 fi
20
21 if [ -z "$zsig" ]; then
22     if [ -e "$GIT_DIR/description" ]; then
23         zsig=`cat "$GIT_DIR/description"`
24     fi
25     if [ -z "$zsig" ] || [ "$zsig" = "Unnamed repository; edit this file to name it for gitweb." ]; then
26         zsig=$(basename "$(readlink -f "$GIT_DIR")")
27         if [ "$zsig" = ".git" ]; then
28             zsig=$(basename "$(readlink -f "$GIT_DIR/..")")
29         fi
30     fi
31 fi
32
33 if [ -z "$class" ]; then
34   echo "I don't know where to send a commit zephyr!" >&2
35   echo "Please set the zephyr.class config variable in" >&2
36   echo "$PWD/config." >&2
37   exit 1
38 fi
39 while read oldrev newrev refname; do
40   if [ "$oldrev" = "0000000000000000000000000000000000000000" ]; then
41     # dammit git
42     zwrite -c "$class" -i "${instance:-$(basename "$refname")}" -s "$zsig: $refname" -d \
43       -m "New branch $refname created, currently at $newrev."
44     continue
45   fi
46   git rev-list --first-parent --reverse "$oldrev..$newrev" | while read rev; do
47     shortrev=`git log -1 --pretty=format:%h "$rev"`
48     (git show --stat -M $usecolor "$rev" |
49      sed -e 's/@/@@/g' \
50          -e 's/}/@(})/g' \
51          -e 's/\e\[m/}@{/g' \
52          -e 's/\e\[33m/@color(yellow)/g' \
53          -e 's/\e\[31m/@color(red)/g' \
54          -e 's/\e\[32m/@color(green)/g' \
55          -e '1s/^/@{/' \
56          -e '$s/$/}/') |
57     zwrite -c "$class" -i "${instance:-$shortrev}" -s "$zsig: $refname" -d
58   done
59 done