3 # Invoked from taskd/taskd.pl
10 [ "$cfg_permission_control" != "Hooks" ] ||
umask 000
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 mail="$(config_get owner)"
26 echo "Initiating mirroring..."
28 svn
://* | svn
+http
://* | svn
+https
://*)
29 # We just remove svn+ here, so svn+http://... becomes http://...
30 # We also remove a trailing '/' to match what git-svn will do
33 # We must use GIT_DIR=. here or ever so "helpful" git-svn will
34 # create a .git subdirectory!
35 GIT_DIR
=. git svn init
-s "$svnurl"
36 # We need to remember this url so we can detect changes because
37 # ever so "helpful" git-svn may shorten it!
38 config_set svnurl
"$svnurl"
39 # At this point, since we asked for a standard layout (-s) git-svn
40 # may have been "helpful" and adjusted our $svnurl to a prefix and
41 # then glued the removed suffix onto the front of any svn-remote.svn.*
42 # config items. We could avoid this by not using the '-s' option
43 # but then we might not get all the history. If, for example, we
44 # are cloning an http://svn.example.com/repos/public repository that
45 # early in its history moved trunk => public/trunk we would miss that
46 # earlier history without allowing the funky shorten+prefix behavior.
47 # So we read back the svn-remote.svn.fetch configuration and compute
48 # the prefix. This way we are sure to get the correct prefix.
49 gitsvnurl
="$(git config --get svn-remote.svn.url || :)"
50 gitsvnfetch
="$(git config --get-all svn-remote.svn.fetch | tail -1 || :)"
51 gitsvnprefix
="${gitsvnfetch%trunk:refs/remotes/trunk}"
52 # Ask git-svn to store everything in the normal non-remote
53 # locations being careful to use the correct prefix
54 git config
--replace-all svn-remote.svn.fetch
"${gitsvnprefix}trunk:refs/heads/master"
55 git config
--replace-all svn-remote.svn.branches
"${gitsvnprefix}branches/*:refs/heads/*"
56 git config
--replace-all svn-remote.svn.tags
"${gitsvnprefix}tags/*:refs/tags/*"
57 # look for additional non-standard directories to fetch
58 # check for standard layout at the same time
61 { svn
ls "$gitsvnurl/${gitsvnprefix}" 2>/dev
/null ||
:; } | \
62 { while read file; do case $file in
63 # skip the already-handled standard ones and any with a space or tab
65 trunk
/|branches
/|tags
/) foundstd
=1;;
66 # only fetch extra directories from the $svnurl root (not any files)
67 *?
/) git config
--add svn-remote.svn.fetch \
68 "${gitsvnprefix}${file%/}:refs/heads/${file%/}";;
71 # if files found and no standard directories present use a simpler layout
72 if [ -z "$foundstd" ] && [ -n "$foundfile" ]; then
73 git config
--unset svn-remote.svn.branches
74 git config
--unset svn-remote.svn.tags
75 git config
--replace-all svn-remote.svn.fetch
':refs/heads/master'
77 # Again, be careful to use GIT_DIR=. here or else new .git subdirectory!
78 GIT_DIR
=. git svn fetch
--quiet
79 # git svn does not preserve group permissions in the svn subdirectory
80 chmod -R ug
+rw
,o
+r svn
81 # git svn also leaves behind ref turds that end with @nnn
82 # We get rid of them now
84 { while read sha1 ref
; do
86 ?
*@
[1-9]|?
*@
[1-9][0-9]|?
*@
[1-9][0-9][0-9]|?
*@
[1-9][0-9][0-9][0-9]|\
87 ?
*@
[1-9][0-9][0-9][0-9][0-9]|?
*@
[1-9][0-9][0-9][0-9][0-9][0-9]|\
88 ?
*@
[1-9][0-9][0-9][0-9][0-9][0-9][0-9]|\
89 ?
*@
[1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])
90 git update-ref
-d "$ref"
95 httpurl
="${url/darcs:\/\//http://}"
96 "$cfg_basedir"/bin
/darcs-fast-export
--export-marks=$
(pwd)/dfe-marks
"$httpurl" | \
97 git fast-import
--export-marks=$
(pwd)/gfi-marks
98 # This is here because by default only the exit code of
99 # git fast-import is checked
100 [ ${PIPESTATUS[0]} = 0 -a ${PIPESTATUS[1]} = 0 ]
103 # we just remove bzr:// here, a typical bzr url is just
105 bzrurl
="${url#bzr://}"
106 bzr fast-export
--export-marks=$
(pwd)/bfe-marks
"$bzrurl" | \
107 git fast-import
--export-marks=$
(pwd)/gfi-marks
108 [ ${PIPESTATUS[0]} = 0 -a ${PIPESTATUS[1]} = 0 ]
111 git remote
rm origin
>/dev
/null
2>&1 ||
:
112 git remote add
--mirror origin
"$url"
113 GIT_SSL_NO_VERIFY
=1 git remote update
114 git remote prune origin
118 # The objects subdirectories permissions must be updated now.
119 # In the case of a dumb http clone, the permissions will not be correct
120 # (missing group write) despite the core.sharedrepository=1 setting!
121 # The objects themselves seem to have the correct permissions.
122 # This problem appears to have been fixed in the most recent git versions.
124 [ "$cfg_permission_control" != "Hooks" ] || perms
=go
+w
125 chmod $perms $
(find objects
-maxdepth 1 -type d
) 2>/dev
/null ||
:
128 echo "Final touches..."
129 git update-server-info
131 mail -s "[$cfg_name] $proj clone completed" "$mail,$cfg_admin" <<EOT
132 Congratulations! The clone of project $proj just completed.
135 * GitWeb interface: $cfg_gitweburl/$projdir
136 * Project settings: $cfg_webadmurl/editproj.cgi?name=$proj
141 echo "Mirroring finished successfuly!"
142 rm .clone_in_progress