Girocco::Project: more robust method to detect errors when changing HEAD
[girocco.git] / jobd / update.sh
blob36f7531cae7f7cad35b770f5b306a58a352172ff
1 #!/bin/bash
3 . @basedir@/shlib.sh
5 # darcs fast-export | git fast-import with error handling
6 git_darcs_fetch() {
7 "$cfg_basedir"/bin/darcs-fast-export --export-marks=$(pwd)/dfe-marks --import-marks=$(pwd)/dfe-marks "$1" | \
8 git fast-import --export-marks=$(pwd)/gfi-marks --import-marks=$(pwd)/gfi-marks
9 [ ${PIPESTATUS[0]} = 0 -a ${PIPESTATUS[1]} = 0 ]
10 return $?
13 # bzr fast-export | git fast-import with error handling
14 git_bzr_fetch() {
15 bzr fast-export --export-marks=$(pwd)/dfe-marks --import-marks=$(pwd)/dfe-marks "$1" | \
16 git fast-import --export-marks=$(pwd)/gfi-marks --import-marks=$(pwd)/gfi-marks
17 [ ${PIPESTATUS[0]} = 0 -a ${PIPESTATUS[1]} = 0 ]
18 return $?
20 set -e
22 proj="$1"
23 cd "$cfg_reporoot/$proj.git"
25 if check_interval lastrefresh $cfg_min_mirror_interval; then
26 progress "= [$proj] update skip (last at $(config_get lastrefresh))"
27 exit 0
29 progress "+ [$proj] update (`date`)"
31 bang_setup
32 bang_once=1
33 bang_action="update"
35 url="$(config_get baseurl)"
36 mail="$(config_get owner)"
38 bang git for-each-ref --format '%(refname) %(objectname)' >.refs-before
40 case "$url" in
41 svn://* | svn+http://* | svn+https://*)
42 GIT_DIR=. bang git svn fetch
43 GIT_DIR=. bang git fetch
45 darcs://*)
46 httpurl="${url/darcs:\/\//http://}"
47 bang git_darcs_fetch "$httpurl"
49 bzr://*)
50 bzrurl="${url#bzr://}"
51 bang git_bzr_fetch "$bzrurl"
54 [ "$url" = "$(config_get remote.origin.url)" ] || bang config_set_raw remote.origin.url "$url"
55 bang git remote update
56 bang git remote prune origin
58 esac
60 bang git update-server-info
61 bang config_set lastrefresh "$(date -R)"
63 # Look at which refs changed and trigger ref-change for these
64 bang git for-each-ref --format '%(refname) %(objectname)' >.refs-after
65 sockpath="$cfg_chroot/etc/taskd.socket"
66 if [ -S "$sockpath" ] && ! cmp -s .refs-before .refs-after; then
67 join -j 1 .refs-before .refs-after |
68 while read ref old new; do
69 [ "$old" != "$new" ] || continue
70 echo "ref-change -1 $proj $old $new $ref" | nc.openbsd -w 1 -U "$sockpath"
71 done
72 join -j 1 -v 1 .refs-before .refs-after |
73 while read ref old; do
74 echo "ref-change -1 $proj $old 0000000000000000000000000000000000000000 $ref" | nc.openbsd -w 1 -U "$sockpath"
75 done
76 join -j 1 -v 2 .refs-before .refs-after |
77 while read ref new; do
78 echo "ref-change -1 $proj 0000000000000000000000000000000000000000 $new $ref" | nc.openbsd -w 1 -U "$sockpath"
79 done
82 rm -f .refs-before .refs-after
84 if [ -e .banged ]; then
85 echo "$proj update succeeded - failure recovery" | mail -s "[$cfg_name] $proj update succeeded" "$mail,$cfg_admin"
86 rm .banged
89 progress "- [$proj] update (`date`)"