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 / git_big_push.php (851e1ec6a100997e9354e33f7ce37df0e415843a) (3,086B) (mode 100644) [raw]
<?php
error_reporting(E_ALL | E_STRICT);
ini_set("track_errors", "On");

$test_normal = TRUE;

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

rg_log_set_file("git_big_push.log");

require_once("common.php");

$_testns = 'git_big_push';


$rg_git_debug = 100;


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


putenv('git_username=' . $rg_ui['username']);
putenv('git_password=' . $rg_ui['pass']);
putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass');

$remote = escapeshellarg($repo['clone_url_http']);


rg_log('');
if (!file_exists('temp_repos/git_small_obj')) {
	rg_log_enter('Testing push with a lot of small objects (create repo)...');
	$r = rg_exec('mkdir -p temp_repos && cd temp_repos'
		. ' && mkdir git_small_obj.tmp && cd git_small_obj.tmp'
		. ' && git init'
		. ' && (for i in `seq 0 500`; do'
		. ' dd if=/dev/urandom of=a-${i} bs=10000 count=1'
		. ' && git add a-${i}'
		. ' && git commit -m "aaa-${i}";'
		. ' done)'
		. ' && git remote add origin ' . $remote
		. ' && cd .. && mv git_small_obj.tmp git_small_obj',
		'', FALSE, FALSE, FALSE);
	if ($r['ok'] != 1) {
		rg_log_ml('r: ' . print_r($r, TRUE));
		rg_log_ml('Could not push lots of small files: ' . $r['errmsg'] . '!');
		exit(1);
	}
	rg_log_exit();
}

rg_log('');
rg_log_enter('Testing push with a lot of small objects (push)...');
$r = rg_exec('cd temp_repos/git_small_obj'
	. ' && git remote set-url origin ' . $remote
	. ' && git push --force origin master',
	'', FALSE, FALSE, FALSE);
if ($r['ok'] != 1) {
	rg_log_ml('r: ' . print_r($r, TRUE));
	rg_log_ml('Could not push lots of small files: ' . $r['errmsg'] . '!');
	exit(1);
}
rg_log_exit();


rg_log('');
if (!file_exists('temp_repos/git_big_push')) {
	rg_log_enter('Testing push with a big file (create repo)...');
	$r = rg_exec('mkdir -p temp_repos && cd temp_repos'
		. ' && mkdir git_big_push.tmp && cd git_big_push.tmp'
		. ' && git init'
		. ' && git remote add origin ' . $remote
		. ' && dd if=/dev/zero of=a bs=1M count=2'
		. ' && git add a'
		. ' && git commit -a -m "aaa"'
		. ' && git config http.postBuffer 8000'
		. ' && cd .. && mv git_big_push.tmp git_big_push',
		'', FALSE, FALSE, FALSE);
	if ($r['ok'] != 1) {
		rg_log_ml('r: ' . print_r($r, TRUE));
		rg_log_ml('Could not exec repo script (part 1): ' . $r['errmsg'] . '!');
		exit(1);
	}
	rg_log_exit();
}

rg_log('');
rg_log_enter('Testing push with a big file (push)...');
$r = rg_exec('cd temp_repos/git_big_push'
	. ' && git remote set-url origin ' . $remote
	. ' && git push --force origin master',
	'', FALSE, FALSE, FALSE);
if ($r['ok'] != 1) {
	if (!strstr($r['errmsg'], 'git config http.postBuffer')) {
		rg_log_ml('Could not exec repo script (part 2): ' . $r['errmsg'] . '!');
		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