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 / source.php (103ac9710b21ff8f906f75cff3c01b07fbd08820) (2,629B) (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("source.log");

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

$_testns = 'source';
$rg_cache_enable = TRUE;


rg_test_create_user($db, $rg_ui);
rg_log('Created user ' . $rg_ui['uid']);
rg_test_create_repo($db, $rg_ui, $repo);
rg_log('Created repo ' . $repo['repo_id']);
$r = test_login($test_url, $rg_ui, $good_sid);
if ($r === FALSE) {
	rg_log("Cannot login!");
	exit(1);
}


rg_log('');
rg_log_enter('Uploading a key...');
rg_test_upload_ssh_key($db, $rg_ui, 'source', $good_sid);
rg_log_exit();


rg_log('');
rg_log_enter('Trying to push master with an empty file...');
$cmsg = time() . ' commit message';
$remote = 'ssh://rocketgit@' . $rg_ssh_host . ':' .$rg_ssh_port
	. '/user/' . escapeshellarg($rg_ui['username'])
	. '/' . escapeshellarg($repo['name']);
$r = rg_exec('mkdir -p temp_repos && cd temp_repos'
	. ' && rm -rf .source && mkdir .source && cd .source'
	. ' && git init && git commit --allow-empty -m "' . $cmsg . '"'
	. ' && git remote add origin ' . $remote
	. ' && export GIT_SSH_COMMAND="ssh -v -o IdentityFile=../../keys/source -o IdentitiesOnly=yes"'
	. ' && git push origin master',
	'', FALSE, FALSE);
if ($r['ok'] != 1) {
	rg_log_ml('out: ' . $r['errmsg']);
	rg_log("Seems I cannot push master! err=$err");
	exit(1);
}
$data = array();
$headers = array("Cookie: sid=" . $good_sid);
rg_log('Check "log" menu...');
$r = do_req($test_url . '/user/' . rawurlencode($rg_ui['username'])
        . '/' . rawurlencode($repo['name']) . '/source/log',
        $data, $headers);
if ($r === FALSE) {
        rg_log('Cannot load source/log page!');
        exit(1);
}
if (!strstr($r['body'], $cmsg)) {
        rg_log_ml('r: ' . print_r($r, TRUE));
        rg_log('I cannot find [' . $cmsg . '] inside the body!');
        exit(1);
}
rg_log('Check "Tree" menu...');
$r = do_req($test_url . '/user/' . rawurlencode($rg_ui['username'])
        . '/' . rawurlencode($repo['name']) . '/source/tree',
        $data, $headers);
if ($r === FALSE) {
        rg_log('Cannot load source/tree page!');
        exit(1);
}
if (!strstr($r['body'], 'Tree is empty.')) {
        rg_log_ml('r: ' . print_r($r, TRUE));
        rg_log('I cannot find [Tree is empty.] inside the body!');
        exit(1);
}

rg_log_exit();


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