Teach Girocco to mirror http:// style SVN repos
[girocco/testingthisout.git] / taskd / clone.sh
blobf99d04645cca0fe4022a0b4d886dcfea3740b71f
1 #!/bin/bash
3 # Invoked from taskd/taskd.pl
5 . @basedir@/shlib.sh
7 set -e
9 projdir="$1"
10 proj="${projdir%.git}"
12 cd "$cfg_reporoot/$projdir"
13 trap "echo '@OVER@'; touch .clone_failed" EXIT
14 url="$(config_get baseurl)"
16 if [ "$cfg_project_owners" = "source" ]; then
17 config_set owner "$(stat -c %U "$url" 2>/dev/null)"
20 mail="$(config_get owner)"
22 # Initial mirror
23 echo "Initiating mirroring..."
24 case "$url" in
25 svn://* | svn+http://*)
26 # we just remote svn+ here, so svn+http://... becomes http://...
27 svnurl="${url#svn+}"
28 GIT_DIR=. git svn init -s "$svnurl"
29 GIT_DIR=. git svn fetch
30 # Neat Trick suggested by Miklos Vajna
31 GIT_DIR=. git config remote.origin.url .
32 GIT_DIR=. git config remote.origin.fetch +refs/remotes/heads/*:refs/heads/*
33 GIT_DIR=. git config remote.origin.fetch +refs/remotes/trunk:refs/heads/master
34 GIT_DIR=. git config remote.origin.fetch +refs/remotes/tags/*:refs/tags/*
35 GIT_DIR=. git fetch
37 darcs://*)
38 httpurl="${url/darcs:\/\//http://}"
39 "$cfg_basedir"/bin/darcs-fast-export --export-marks=$(pwd)/dfe-marks "$httpurl" | \
40 git fast-import --export-marks=$(pwd)/gfi-marks
41 # This is here because by default only the exit code of
42 # git fast-import is checked
43 [ ${PIPESTATUS[0]} = 0 -a ${PIPESTATUS[1]} = 0 ]
45 bzr://*)
46 # we just remove bzr:// here, a typical bzr url is just
47 # "lp:foo"
48 bzrurl="${url#bzr://}"
49 bzr fast-export --export-marks=$(pwd)/bfe-marks "$bzrurl" | \
50 git fast-import --export-marks=$(pwd)/gfi-marks
51 [ ${PIPESTATUS[0]} = 0 -a ${PIPESTATUS[1]} = 0 ]
54 git remote rm origin >/dev/null 2>&1 || :
55 git remote add --mirror origin "$url"
56 git remote update
57 git remote prune origin
59 esac
61 # The rest
62 echo "Final touches..."
63 git update-server-info
64 trap "" EXIT
65 mail -s "[$cfg_name] $proj clone completed" "$mail,$cfg_admin" <<EOT
66 Congratulations! The clone of project $proj just completed.
68 * Source URL: $url
69 * GitWeb interface: $cfg_gitweburl/$projdir
70 * Project settings: $cfg_webadmurl/editproj.cgi?name=$proj
72 Have a lot of fun.
73 EOT
75 echo "Mirroring finished successfuly!"
76 rm .clone_in_progress
77 echo "@OVER@"