xaizek / rocketgit (License: AGPLv3+) (since 2018-12-09)
Light and fast Git hosting solution suitable to serve both as a hub or as a personal code storage with its tickets, pull requests, API and much more.
<root> / tests / git2.php (7b55f2e717f5a5179f2de361b41da25ed4922cd0) (2,933B) (mode 100644) [raw]
<?php
error_reporting(E_ALL | E_STRICT);
ini_set("track_errors", "On");

$INC = dirname(__FILE__) . "/../inc";
require_once(dirname(__FILE__) . "/config.php");
require_once($INC . "/init.inc.php");
require_once($INC . "/git.inc.php");
require_once("helpers.inc.php");
require_once("http.inc.php");

rg_log_set_file("git2.log");

$rg_sql = "host=localhost user=rocketgit dbname=rocketgit connect_timeout=10";
$rg_no_db = TRUE;
require_once("common.php");

$_testns = 'git2';
$rg_cache_enable = TRUE;

system("./git2.sh &>git2.log");
if (!file_exists("git2/.git/refs/heads/group1/branch1")) {
	rg_log("Something wrong generating the git2 tree: "
		. file_get_contents("git2.log"));
	exit(1);
}

// test rg_git_refs
$refs = rg_git_refs("git2/.git");
if (strcmp($refs['tag'][0], "unannot1") != 0) {
	rg_log("Could not create an un-annotated tag: " . print_r($refs, TRUE));
	exit(1);
}
if (strcmp($refs['tag'][1], "v1.0") != 0) {
	rg_log("Could not create an annotated tag: " . print_r($refs, TRUE));
	exit(1);
}
if (strcmp($refs['branch'][0], "group1/branch1") != 0) {
	rg_log("Could not create branch group1/branch1: " . print_r($refs, TRUE));
	exit(1);
}

// This test makes sense only on my devel machine
if (php_uname("n") != "r1.embedromix.ro") {
	rg_log("OK!");
	exit(0);
}


rg_log("Creating a user...");
rg_test_create_user($db, $rg_ui);
rg_test_create_repo($db, $rg_ui, $repo);
$r = test_login($test_url, $rg_ui, $good_sid);
if ($r === FALSE) {
	rg_log("Cannot login!");
	exit(1);
}

$key = rg_test_upload_ssh_key($db, $rg_ui, "git2", $good_sid);

$remote = 'ssh://rocketgit@rgtest/user/' . escapeshellarg($rg_ui['username'])
	. '/' . escapeshellarg($repo['name']);
system("cd git2; git remote add origin $remote");
exec("cd git2; git push origin master", $out, $err);
if ($err != 0) {
	rg_log_ml('out: ' . print_r($out, TRUE));
	rg_log("Seems I cannot push master! err=$err");
	exit(1);
}
exec("cd git2; git push --tags origin", $out, $err);
if ($err != 0) {
	rg_log_ml('out: ' . print_r($out, TRUE));
	rg_log("Seems I cannot push tags! err=$err");
	exit(1);
}


$commit = trim(file_get_contents('git2/.git/refs/heads/master'));
rg_log("Load master from .git: $commit");

rg_log("Checking on web that everything is OK...");
$data = array();
$headers = array("Cookie: sid=" . $good_sid);
$r = do_req($test_url . '/user/' . rawurlencode($rg_ui['username'])
	. '/' . rawurlencode($repo['name']) . '/source/log/commit/'
	. $commit, $data, $headers);
if ($r === FALSE) {
	rg_log("Cannot load master commit!");
	exit(1);
}

rg_log("Checking on web that tag is OK...");
$data = array();
$headers = array("Cookie: sid=" . $good_sid);
$r = do_req($test_url . '/user/' . rawurlencode($rg_ui['username'])
	. '/' . rawurlencode($repo['name'])
	. '/source/tree/tag/unannot1/blob/a', $data, $headers);
if (strstr($r['body'], 'a signature') === FALSE) {
	rg_log_ml("Cannot see the tag: " . print_r($r, TRUE));
	exit(1);
}


rg_log("OK!");
?>
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/rocketgit

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/rocketgit

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master