From: Paul J R Date: Wed, 24 Oct 2012 18:48:50 +0000 (+1100) Subject: Added clone for non-remote X-Git-Url: http://git.pjr.cc/?p=gwvp-mini.git;a=commitdiff_plain;h=90c1b8ddcf48b3f13f143954a81f231591955915 Added clone for non-remote --- diff --git a/TODO b/TODO new file mode 100644 index 0000000..f7211b8 --- /dev/null +++ b/TODO @@ -0,0 +1,16 @@ +First (for beta release): + +need a standard git log parser/collector deal +need to add activity for repo creation +get clone working properly +put "system'd" stuff into variables + +Next: + +ability to git-view a source code base? +Chat between people on the site - simplistic chat (or maybe just a simple form that'll send an email) + +Long term: + +link multiple sites together +deal with pull's between forks of a repo \ No newline at end of file diff --git a/gwvpmini/gwvpmini.php b/gwvpmini/gwvpmini.php index 25642cb..0abc29f 100644 --- a/gwvpmini/gwvpmini.php +++ b/gwvpmini/gwvpmini.php @@ -11,6 +11,7 @@ require_once("gwvpmini_view.php"); require_once("gwvpmini_activity.php"); require_once("gwvpmini_register.php"); require_once("gwvpmini_user.php"); +require_once("gwvpmini_debug.php"); // require_once("gwvpmini_chat.php"); TODO: disabling chat for now to work on more important interfaces first if($IS_WEB_REQUEST) { if(gwvpmini_isLoggedIn()) if(gwvpmini_isUserAdmin()) { diff --git a/gwvpmini/gwvpmini_activity.php b/gwvpmini/gwvpmini_activity.php index 107cb48..a81a522 100644 --- a/gwvpmini/gwvpmini_activity.php +++ b/gwvpmini/gwvpmini_activity.php @@ -71,7 +71,8 @@ function gwvpmini_HomePageActivityLog() { global $BASE_URL; - $id = $_SESSION["id"]; + $id = -1; + if(isset($_SESSION["id"])) $id = $_SESSION["id"]; if($id < 0) { $ents = gwvpmini_GetActivityLog(); @@ -81,7 +82,7 @@ function gwvpmini_HomePageActivityLog() echo "

News

"; echo ""; - foreach($ents as $vals) { + if($ents != null) foreach($ents as $vals) { /* * $ret[$nent]["type"] = $vals["activity_type"]; $ret[$nent]["date"] = $vals["activity_date"]; diff --git a/gwvpmini/gwvpmini_db.php b/gwvpmini/gwvpmini_db.php index d3d1057..8b3fd26 100644 --- a/gwvpmini/gwvpmini_db.php +++ b/gwvpmini/gwvpmini_db.php @@ -753,13 +753,13 @@ function gwvpmini_setConfigVal($confname, $confval) return $conn->query($sql); } -function gwvpmini_AddRepo($name, $desc, $ownerid, $clonefrom) +function gwvpmini_AddRepo($name, $desc, $ownerid, $defperms, $clonefrom) { // error_log("addrepo in db for $name, $desc, $ownerid"); $conn = gwvpmini_ConnectDB(); - $perms["b"] = "a"; + $perms["b"] = $defperms; $encperms = base64_encode(serialize($perms)); diff --git a/gwvpmini/gwvpmini_debug.php b/gwvpmini/gwvpmini_debug.php new file mode 100644 index 0000000..80cf2e0 --- /dev/null +++ b/gwvpmini/gwvpmini_debug.php @@ -0,0 +1,46 @@ +query("select * from repos"); + foreach($res as $row) { + $repo = $row["repos_name"]; + $perms = $row["repos_perms"]; + echo "
Repo: $repo:
";
+		print_r(unserialize(base64_decode($perms)));
+		echo "
"; + } +} +?> \ No newline at end of file diff --git a/gwvpmini/gwvpmini_gitbackend.php b/gwvpmini/gwvpmini_gitbackend.php index 5aeedcf..5a6c055 100644 --- a/gwvpmini/gwvpmini_gitbackend.php +++ b/gwvpmini/gwvpmini_gitbackend.php @@ -107,7 +107,8 @@ function gwvpmini_gitBackendInterface() // we do an update server cause its weird and i cant figure out when it actually needs to happen chdir("$repo_base/$repo.git"); - exec("/usr/bin/git update-server-info"); + // dont believe i have to do this + //exec("/usr/bin/git update-server-info"); if(!file_exists("$repo_base/$repo.git/hooks/pre-receive") || !file_exists("$repo_base/$repo.git/hooks/update")) { // error_log("WRITING HOOKS"); @@ -413,22 +414,25 @@ function gwvpmini_repoExists($name) // 0 - anyone can clone/read, only owner can write // 1 - noone can clone/read, repo is visible (i.e. name), only owner can read/write repo // 2 - only owner can see anything -function gwvpmini_createGitRepo($name, $ownerid, $desc, $clonefrom) +function gwvpmini_createGitRepo($name, $ownerid, $desc, $defperms, $clonefrom, $isremoteclone) { $repo_base = gwvpmini_getConfigVal("repodir"); if($clonefrom !== false) { - + error_log("how did i end up in clonefrom? $clonefrom"); + if(!$isremoteclone) { + exec("/usr/bin/git clone --bare $repo_base/$clonefrom.git $repo_base/$name.git >> /tmp/gitlog 2>&1"); + } } else { // phew, this works, but i tell you this - bundles arent quite as nice as they should be // error_log("would create $repo_base/$name.git"); - exec("/usr/bin/git init $repo_base/$name.git --bare > /tmp/gitlog 2>&1"); + exec("/usr/bin/git init $repo_base/$name.git --bare >> /tmp/gitlog 2>&1"); chdir("$repo_base/$name.git"); exec("/usr/bin/git update-server-info"); // gwvpmini_AddRepo($reponame, $repodesc, $repoowner, $defaultperms = 0) - gwvpmini_AddRepo($name, $desc, $ownerid, $clonefrom); + gwvpmini_AddRepo($name, $desc, $ownerid, $defperms, $clonefrom); } return true; diff --git a/gwvpmini/gwvpmini_gitrepo.php b/gwvpmini/gwvpmini_gitrepo.php index d642c92..ba00862 100644 --- a/gwvpmini/gwvpmini_gitrepo.php +++ b/gwvpmini/gwvpmini_gitrepo.php @@ -232,11 +232,30 @@ function gwvpmini_RepoCreate() if($clonefrom !== false && $fromremote == false) { // check the local repo exists $rn = gwvpmini_getRepo(null, $clonefrom, null); + $uid = $_SESSION["id"]; + if($rn == false) { - gwvpmini_SendMessage("error", "local repo $clonefrom given as upstream clone, however $clonefrom doesnt exist on this site"); + gwvpmini_SendMessage("error", "local repo $clonefrom given as upstream clone, however $clonefrom doesnt exist on this site (or you cant read it)"); header("Location: $BASE_URL/repos"); return; } + + // resolve repo permissions on the read/clone + if(gwvpmini_GetRepoPerm($rn, $uid) < 1) { + gwvpmini_SendMessage("error", "local repo $clonefrom given as upstream clone, however $clonefrom doesnt exist on this site (or you cant read it)"); + header("Location: $BASE_URL/repos"); + return; + } + } + + $defperms = "a"; + switch($_REQUEST["perms"]) { + case "perms-registered": + $defperms = "r"; + break; + case "perms-onlywrite": + $defperms = "x"; + break; } if(!$inputcheck) { @@ -248,7 +267,7 @@ function gwvpmini_RepoCreate() gwvpmini_SendMessage("error", "Repo ".$_REQUEST["reponame"]." already exists"); header("Location: $BASE_URL/repos"); } else { - gwvpmini_createGitRepo($_REQUEST["reponame"], $_SESSION["id"], $_REQUEST["repodesc"], $_REQUEST["perms"], $clonefrom); + gwvpmini_createGitRepo($_REQUEST["reponame"], $_SESSION["id"], $_REQUEST["repodesc"], $defperms, $clonefrom, $fromremote); gwvpmini_SendMessage("info", "Repo ".$_REQUEST["reponame"]." has been created"); header("Location: $BASE_URL/repos"); }