Attempt to fix mirroring (3).
[girocco.git] / taskd / clone.sh
blob5a9ce7438a2b64a1a1a7c7bbd962ec0b3d38142b
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://* | svn+https://*)
26 # we just remote svn+ here, so svn+http://... becomes http://...
27 svnurl="${url#svn+}"
28 GIT_DIR=. git svn clone "$svnurl" .
29 # Neat Trick suggested by Miklos Vajna
30 GIT_DIR=. git config remote.origin.url .
31 GIT_DIR=. git config remote.origin.fetch '+refs/remotes/heads/*:refs/heads/*'
32 GIT_DIR=. git config --add remote.origin.fetch '+refs/remotes/trunk:refs/heads/master'
33 GIT_DIR=. git config --add remote.origin.fetch '+refs/remotes/tags/*:refs/tags/*'
34 GIT_DIR=. git fetch
36 darcs://*)
37 httpurl="${url/darcs:\/\//http://}"
38 "$cfg_basedir"/bin/darcs-fast-export --export-marks=$(pwd)/dfe-marks "$httpurl" | \
39 git fast-import --export-marks=$(pwd)/gfi-marks
40 # This is here because by default only the exit code of
41 # git fast-import is checked
42 [ ${PIPESTATUS[0]} = 0 -a ${PIPESTATUS[1]} = 0 ]
44 bzr://*)
45 # we just remove bzr:// here, a typical bzr url is just
46 # "lp:foo"
47 bzrurl="${url#bzr://}"
48 bzr fast-export --export-marks=$(pwd)/bfe-marks "$bzrurl" | \
49 git fast-import --export-marks=$(pwd)/gfi-marks
50 [ ${PIPESTATUS[0]} = 0 -a ${PIPESTATUS[1]} = 0 ]
53 git remote rm origin >/dev/null 2>&1 || :
54 git remote add --mirror origin "$url"
55 git remote update
56 git remote prune origin
58 esac
60 # The rest
61 echo "Final touches..."
62 git update-server-info
63 trap "" EXIT
64 mail -s "[$cfg_name] $proj clone completed" "$mail,$cfg_admin" <<EOT
65 Congratulations! The clone of project $proj just completed.
67 * Source URL: $url
68 * GitWeb interface: $cfg_gitweburl/$projdir
69 * Project settings: $cfg_webadmurl/editproj.cgi?name=$proj
71 Have a lot of fun.
72 EOT
74 echo "Mirroring finished successfuly!"
75 rm .clone_in_progress
76 echo "@OVER@"