jobd/update.sh: ref-change new - fix variable name
[girocco.git] / jobd / update.sh
blob401bc6801c17a19076f4badfee3070f5ffaab1d0
1 #!/bin/bash
3 . @basedir@/shlib.sh
5 set -e
7 proj="$1"
8 cd "$cfg_reporoot/$proj.git"
10 if check_interval lastrefresh $cfg_min_mirror_interval; then
11 progress "= [$proj] update skip (last at $(config_get lastrefresh))"
12 exit 0
14 progress "+ [$proj] update (`date`)"
16 bang_setup
17 bang_once=1
18 bang_action="update"
20 url="$(config_get baseurl)"
21 mail="$(config_get owner)"
23 bang git for-each-ref --format '%(refname) %(objectname)' >.refs-before
25 case "$url" in
26 svn://*)
27 GIT_DIR=. bang git svn fetch
28 GIT_DIR=. bang git fetch
31 bang git remote update
32 bang git remote prune origin
34 esac
36 bang git update-server-info
37 bang config_set lastrefresh "$(date -R)"
39 # Look at which refs changed and trigger ref-change for these
40 bang git for-each-ref --format '%(refname) %(objectname)' >.refs-after
41 sockpath="$cfg_chroot/etc/taskd.socket"
42 if [ -S "$sockpath" ] && ! cmp -s .refs-before .refs-after; then
44 join -j 1 .refs-before .refs-after |
45 while read ref old new; do
46 [ "$old" != "$new" ] || continue
47 echo "ref-change -1 $proj $old $new $ref"
48 done
49 join -j 1 -v 1 .refs-before .refs-after |
50 while read ref old; do
51 echo "ref-change -1 $proj $old 0000000000000000000000000000000000000000 $ref"
52 done
53 join -j 1 -v 2 .refs-before .refs-after |
54 while read ref new; do
55 echo "ref-change -1 $proj 0000000000000000000000000000000000000000 $new $ref"
56 done
57 } | nc.openbsd -w 1 -U "$sockpath"
60 rm -f .refs-before .refs-after
62 if [ -e .banged ]; then
63 echo "$proj update succeeded - failure recovery" | mail -s "[$cfg_name] $proj update succeeded" "$mail,$cfg_admin"
64 rm .banged
67 progress "- [$proj] update (`date`)"