<?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("helpers.inc.php");
require_once("http.inc.php");
rg_log_set_file("git-sha256.log");
require_once("common.php");
$_testns = 'git-sha256';
rg_log('');
rg_log_enter('Preparing repo...');
$r = rg_exec('mkdir -p temp_repos'
. ' && rm -rf temp_repos/git-sha256'
. ' && mkdir temp_repos/git-sha256'
. ' && cd temp_repos/git-sha256'
. ' && git init --initial-branch=main --object-format=sha256'
. ' && echo "a signature" > bla.txt'
. ' && git add bla.txt'
. ' && git commit -a -m "bla"',
'', FALSE, FALSE, FALSE);
if ($r['ok'] != 1) {
rg_log_ml('out: ' . print_r($r, TRUE));
rg_log('Seems init repo!');
exit(1);
}
rg_log_exit();
rg_test_create_user($db, $rg_ui);
$info = array('id' => $rg_ui['username']);
prepare_http($info);
$repo = array('hash' => 'sha256');
rg_test_create_repo($db, $rg_ui, $repo);
$r = test_login($test_url, $rg_ui);
if ($r === FALSE) {
rg_log("Cannot login!");
exit(1);
}
rg_test_upload_ssh_key($db, $rg_ui, 'git-sha256', $kn);
rg_log('');
rg_log_enter('Trying to push main...');
$remote = 'ssh://rocketgit@' . $rg_ssh_host . ':' .$rg_ssh_port
. '/user/' . escapeshellarg($rg_ui['username'])
. '/' . escapeshellarg($repo['name']);
$r = rg_exec("cd temp_repos/git-sha256 && git remote add origin $remote"
. " && git push origin main",
'', FALSE, FALSE, FALSE);
if ($r['ok'] != 1) {
rg_log_ml('out: ' . print_r($r, TRUE));
rg_log('Seems I cannot push main!');
exit(1);
}
rg_log_exit();
rg_log('');
rg_log_enter('Trying to push tags...');
$r = rg_exec("cd temp_repos/git-sha256 && git push --tags",
'', FALSE, FALSE, FALSE);
if ($r['ok'] != 1) {
rg_log_ml('error: ' . $r['errmsg']);
rg_log("Seems I cannot push tags!");
exit(1);
}
rg_log_exit();
$commit = trim(@file_get_contents('git-sha256/.git/refs/heads/main'));
rg_log("Loaded main from .git: $commit");
rg_log('');
rg_log_enter('Checking on web that everything is OK...');
$data = array();
$headers = array();
$r = do_req($info, $test_url . '/user/' . rawurlencode($rg_ui['username'])
. '/' . rawurlencode($repo['name']) . '/source/log/commit/'
. $commit, $data, $headers);
if ($r === FALSE) {
rg_log("Cannot load main commit!");
exit(1);
}
rg_log_exit();
rg_log('');
rg_log_enter('Checking on web that tag is OK...');
$data = array();
$headers = array();
$r = do_req($info, $test_url . '/user/' . rawurlencode($rg_ui['username'])
. '/' . rawurlencode($repo['name'])
. '/source/tree/tag/unannot1/blob/bla.txt', $data, $headers);
if (strstr($r['body'], 'a signature') === FALSE) {
rg_log_ml("r: " . print_r($r, TRUE));
rg_log_ml('Cannot see \'a signature\'!');
exit(1);
}
rg_log_exit();
rg_log('');
rg_log_enter('Trying to push a sha1 repo into a sha256 repo...');
$r = rg_exec('rm -rf temp_repos/git-sha256'
. ' && mkdir temp_repos/git-sha256'
. ' && cd temp_repos/git-sha256'
. ' && git init --initial-branch=main --object-format sha1'
. ' && echo "bla" > bla.txt && git add bla.txt && git commit -m "bla"'
. ' && git remote add origin ' . $remote
. ' && git push --force origin main',
'', FALSE, FALSE, FALSE);
if (($r['ok'] == 1) || !strstr($r['stderr'], 'the receiving end does not support this repository\'s hash algorithm')) {
rg_log_ml('out: ' . print_r($r, TRUE));
rg_log('Seems I can push sha1 into sha256!');
exit(1);
}
rg_log_exit();
rg_log('OK!');