Remove "personal mob branches" from TODO
[girocco.git] / taskd / clone.sh
blobdbe23fddc8763dbadc232bdb83cfb417a5671699
1 #!/bin/bash
3 # Invoked from taskd/taskd.pl
5 . @basedir@/shlib.sh
7 set -e
9 umask 002
10 [ "$cfg_permission_control" != "Hooks" ] || umask 000
12 projdir="$1"
13 proj="${projdir%.git}"
15 cd "$cfg_reporoot/$projdir"
16 trap "echo '@OVER@'; touch .clone_failed" EXIT
17 url="$(config_get baseurl)"
19 if [ "$cfg_project_owners" = "source" ]; then
20 config_set owner "$(stat -c %U "$url" 2>/dev/null)"
23 mailaddrs="$(config_get owner || :)"
24 [ -z "$cfg_admin" ] ||
25 if [ -z "$mailaddrs" ]; then mailaddrs="$cfg_admin"; else mailaddrs="$mailaddrs,$cfg_admin"; fi
27 # Initial mirror
28 echo "Initiating mirroring..."
29 case "$url" in
30 svn://* | svn+http://* | svn+https://*)
31 # We just remove svn+ here, so svn+http://... becomes http://...
32 # We also remove a trailing '/' to match what git-svn will do
33 svnurl="${url#svn+}"
34 svnurl="${svnurl%/}"
35 # We require svn info to succeed on the URL otherwise it's
36 # simply not a valid URL and without using -s on the init it
37 # will not otherwise be tested until the fetch
38 svn --non-interactive info "$svnurl" > /dev/null
39 # We initially use -s for the init which will possibly shorten
40 # the URL. However, the shortening can fail if a password is
41 # not required for the longer version but is for the shorter,
42 # so try again without -s if the -s version fails.
43 # We must use GIT_DIR=. here or ever so "helpful" git-svn will
44 # create a .git subdirectory!
45 GIT_DIR=. git svn init -s "$svnurl" < /dev/null ||
46 GIT_DIR=. git svn init "$svnurl" < /dev/null
47 # We need to remember this url so we can detect changes because
48 # ever so "helpful" git-svn may shorten it!
49 config_set svnurl "$svnurl"
50 # At this point, since we asked for a standard layout (-s) git-svn
51 # may have been "helpful" and adjusted our $svnurl to a prefix and
52 # then glued the removed suffix onto the front of any svn-remote.svn.*
53 # config items. We could avoid this by not using the '-s' option
54 # but then we might not get all the history. If, for example, we
55 # are cloning an http://svn.example.com/repos/public repository that
56 # early in its history moved trunk => public/trunk we would miss that
57 # earlier history without allowing the funky shorten+prefix behavior.
58 # So we read back the svn-remote.svn.fetch configuration and compute
59 # the prefix. This way we are sure to get the correct prefix.
60 gitsvnurl="$(git config --get svn-remote.svn.url || :)"
61 gitsvnfetch="$(git config --get-all svn-remote.svn.fetch | tail -1 || :)"
62 gitsvnprefix="${gitsvnfetch%%:*}"
63 gitsvnsuffix="${gitsvnprefix##*/}"
64 gitsvnprefix="${gitsvnprefix%$gitsvnsuffix}"
65 # Ask git-svn to store everything in the normal non-remote
66 # locations being careful to use the correct prefix
67 git config --replace-all svn-remote.svn.fetch "${gitsvnprefix}trunk:refs/heads/master"
68 git config --replace-all svn-remote.svn.branches "${gitsvnprefix}branches/*:refs/heads/*"
69 git config --replace-all svn-remote.svn.tags "${gitsvnprefix}tags/*:refs/tags/*"
70 # look for additional non-standard directories to fetch
71 # check for standard layout at the same time
72 foundstd=
73 foundfile=
74 { svn --non-interactive ls "$gitsvnurl/${gitsvnprefix}" 2>/dev/null || :; } | \
75 { while read file; do case $file in
76 # skip the already-handled standard ones and any with a space or tab
77 *' '*|*' '*) :;;
78 trunk/|branches/|tags/) foundstd=1;;
79 # only fetch extra directories from the $svnurl root (not any files)
80 *?/) git config --add svn-remote.svn.fetch \
81 "${gitsvnprefix}${file%/}:refs/heads/${file%/}";;
82 *?) foundfile=1;;
83 esac; done
84 # if files found and no standard directories present use a simpler layout
85 if [ -z "$foundstd" ] && [ -n "$foundfile" ]; then
86 git config --unset svn-remote.svn.branches
87 git config --unset svn-remote.svn.tags
88 git config --replace-all svn-remote.svn.fetch ':refs/heads/master'
89 fi; }
90 # Again, be careful to use GIT_DIR=. here or else new .git subdirectory!
91 GIT_DIR=. git svn fetch --quiet < /dev/null
92 # git svn does not preserve group permissions in the svn subdirectory
93 chmod -R ug+rw,o+r svn
94 # git svn also leaves behind ref turds that end with @nnn
95 # We get rid of them now
96 git show-ref | \
97 { while read sha1 ref; do
98 case "$ref" in
99 ?*@[1-9]|?*@[1-9][0-9]|?*@[1-9][0-9][0-9]|?*@[1-9][0-9][0-9][0-9]|\
100 ?*@[1-9][0-9][0-9][0-9][0-9]|?*@[1-9][0-9][0-9][0-9][0-9][0-9]|\
101 ?*@[1-9][0-9][0-9][0-9][0-9][0-9][0-9]|\
102 ?*@[1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])
103 git update-ref -d "$ref"
104 esac
105 done; }
107 darcs://*)
108 httpurl="${url/darcs:\/\//http://}"
109 "$cfg_basedir"/bin/darcs-fast-export --export-marks=$(pwd)/dfe-marks "$httpurl" | \
110 git fast-import --export-marks=$(pwd)/gfi-marks
111 # This is here because by default only the exit code of
112 # git fast-import is checked
113 [ ${PIPESTATUS[0]} = 0 -a ${PIPESTATUS[1]} = 0 ]
115 bzr://*)
116 # we just remove bzr:// here, a typical bzr url is just
117 # "lp:foo"
118 bzrurl="${url#bzr://}"
119 bzr fast-export --export-marks=$(pwd)/bfe-marks "$bzrurl" | \
120 git fast-import --export-marks=$(pwd)/gfi-marks
121 [ ${PIPESTATUS[0]} = 0 -a ${PIPESTATUS[1]} = 0 ]
124 git remote rm origin >/dev/null 2>&1 || :
125 git remote add --mirror origin "$url"
126 GIT_SSL_NO_VERIFY=1 git remote update
127 GIT_SSL_NO_VERIFY=1 git remote prune origin
129 esac
131 # The objects subdirectories permissions must be updated now.
132 # In the case of a dumb http clone, the permissions will not be correct
133 # (missing group write) despite the core.sharedrepository=1 setting!
134 # The objects themselves seem to have the correct permissions.
135 # This problem appears to have been fixed in the most recent git versions.
136 perms=g+w
137 [ "$cfg_permission_control" != "Hooks" ] || perms=go+w
138 chmod $perms $(find objects -maxdepth 1 -type d) 2>/dev/null || :
140 # Initialize gitweb.lastchange and info/lastactivity
141 git config gitweb.lastchange "$(date '+%a, %d %b %Y %T %z')"
142 git for-each-ref --sort=-committerdate --format='%(committerdate:iso8601)' \
143 --count=1 refs/heads > info/lastactivity
144 [ -s info/lastactivity ] || rm -f info/lastactivity
146 # The rest
147 echo "Final touches..."
148 git update-server-info
149 trap "" EXIT
151 [ -z "$mailaddrs" ] ||
152 mail -s "[$cfg_name] $proj clone completed" "$mailaddrs" <<EOT || :
153 Congratulations! The clone of project $proj just completed.
155 * Source URL: $url
156 * GitWeb interface: $cfg_gitweburl/$projdir
157 * Project settings: $cfg_webadmurl/editproj.cgi?name=$proj
159 Have a lot of fun.
162 echo "Mirroring finished successfuly!"
163 # In case this is a re-mirror, lastgc could have been set already so clear it now
164 git config --unset gitweb.lastgc || :
165 rm .clone_in_progress
166 echo "@OVER@"