1 <?php # vim:ts=2:sw=2:et:
2 /* For licensing and copyright terms, see the file named LICENSE */
3 include '../../inc/common.php';
5 MTrackACL::requireAnyRights('Browser', 'fork');
7 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
8 $rid = $_POST['source'];
9 MTrackACL::requireAnyRights("repo:$rid", 'read');
10 $name = trim($_POST['name']);
12 if (strlen($name) == 0) {
13 throw new Exception("missing name");
15 if (preg_match("/[^a-zA-Z0-9_.-]/", $name)) {
16 throw new Exception("$name contains illegal characters");
18 $owner = mtrack_canon_username(MTrackAuth::whoami());
19 if (preg_match("/[^a-zA-Z0-9_.-]/", $owner)) {
20 throw new Exception("$owner must be a locally defined user");
23 $S = MTrackRepo::loadById($rid);
25 throw new Exception("cannot fork this repo");
28 $P->shortname = $name;
29 if (isset($_POST['repo:parent'])) {
30 // FIXME: ACL check to see if we're allowed to create under the specified
32 $P->parent = $_POST['repo:parent'];
34 $P->parent = "user:$owner";
37 $P->scmtype = $S->scmtype;
38 $P->description = $S->description;
39 $P->clonedfrom = $S->repoid;
41 $CS = MTrackChangeset::begin("repo:X",
42 "Clone repo $S->shortname as $P->shortname");
44 $CS->setObject("repo:$P->repoid");
46 $name = $P->getBrowseRootName();
47 header("Location: ${ABSWEB}browse.php/$name");
51 header("Location: ${ABSWEB}browse.php");