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 (09dc61e066cbb0d4a4f49cf162285f06a97fdd29) (2,582B) (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(__DIR__ . '/helpers.inc.php');
require_once(__DIR__ . '/http.inc.php');

rg_log_set_file("git_big_push.log");

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

$_testns = 'git_big_push';
$rg_cache_enable = TRUE;

$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('');
rg_log_enter('Testing push with a lot of small objects...');
$r = rg_exec('mkdir -p temp_repos && cd temp_repos'
	. ' && rm -rf git_small_obj && mkdir git_small_obj && cd git_small_obj'
	. ' && export GIT_CURL_VERBOSE=1 GIT_TRACE=1 GIT_TRACE_PACKET=1'
	. ' && git init'
	. ' && git remote add origin ' . $remote
	. ' && (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 push --force origin master',
	'', FALSE, FALSE);
if ($r['ok'] != 1) {
	rg_log_ml('Could not push lots of small files: ' . $r['errmsg'] . '!');
	exit(1);
}
rg_log_exit();
//system('rm -rf temp_repos/git_small_obj');


rg_log('');
rg_log_enter('Testing push with a big file...');
$r = rg_exec('mkdir -p temp_repos && cd temp_repos'
	. ' && rm -rf git_big_push && mkdir git_big_push && cd git_big_push'
	. ' && 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',
	'', FALSE, FALSE);
if ($r['ok'] != 1) {
	rg_log_ml('Could not exec repo script (part 1): ' . $r['errmsg'] . '!');
	exit(1);
}
$r = rg_exec('cd temp_repos/git_big_push'
	. ' && export GIT_CURL_VERBOSE=1 GIT_TRACE=1 GIT_TRACE_PACKET=1'
	. ' && git push --force origin master',
	'', 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();
system('rm -rf temp_repos/git_big_push');


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