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> / hooks / update (0bf5fb882203cc95a661ab59e94139c301f3d3e3) (2,500B) (mode 100755) [raw]
#!/usr/bin/php
<?php

//
// This is called by 'update' hook
// Inspired by update.sample in git package
// It is executed before each ref is updated.
//
// TODO: what do we receive when a tag will be created?
//

error_reporting(E_ALL);
ini_set("track_errors", "On");

$_start = microtime(TRUE);

$conf = getenv("ROCKETGIT_CONF_FILE");
if (empty($conf))
	$conf = "/etc/rocketgit/config.php";
require_once($conf);

$INC = $rg_scripts . "/inc";
require_once($INC . "/init.inc.php");
require_once($INC . "/util.inc.php");
require_once($INC . "/log.inc.php");
require_once($INC . "/sql.inc.php");
require_once($INC . "/repo.inc.php");
require_once($INC . "/prof.inc.php");
require_once($INC . "/mr.inc.php");

rg_prof_start("hook-update");

rg_log_set_file($rg_log_dir . "/hook_update.log");

rg_sql_app("rg-hook-update");
$db = rg_sql_open($rg_sql);

$a = array();
$a['login_uid'] = sprintf("%u", getenv("ROCKETGIT_LOGIN_UID"));
$a['login_username'] = getenv("ROCKETGIT_LOGIN_USERNAME");
$a['repo_id'] = sprintf("%u", getenv("ROCKETGIT_REPO_ID"));
$a['ip'] = getenv("ROCKETGIT_IP");
$a['namespace'] = getenv("GIT_NAMESPACE");
$a['repo_path'] = getenv("ROCKETGIT_REPO_PATH");
$a['repo::uid'] = sprintf("%u", getenv("ROCKETGIT_REPO_UID"));

rg_log("Start " . rg_array2string($a));
rg_log("_SERVER: " . rg_array2string($_SERVER));

umask(0022);


$a['refname'] = rg_git_reference($_SERVER['argv'][1]);
if ($a['refname'] === FALSE)
	rg_git_fatal('Invalid reference: ' . rg_git_error() . '!');

$a['old_rev'] = rg_git_rev(@$_SERVER['argv'][2]);
$a['new_rev'] = rg_git_rev(@$_SERVER['argv'][3]);
rg_log("refname=" . $a['refname'] . " old_rev=" . $a['old_rev']
	. " new_rev=" . $a['new_rev']);

if (empty($a['refname']) || empty($a['old_rev']) || empty($a['new_rev']))
	rg_git_fatal("Invalid parameters: ref=[" . $a['refname']
		. "] old=[" . $a['old_rev'] . "] new=[" . $a['new_rev'] . "]!");

if (strcmp($a['new_rev'], $rg_git_zero) == 0)
	$a['new_rev_type'] = rg_git_type($a['old_rev']);
else
	$a['new_rev_type'] = rg_git_type($a['new_rev']);
rg_log("new_rev_type=" . $a['new_rev_type']);

if (strncmp($a['refname'], "refs/tags/", 10) == 0) {
	rg_git_update_tag($db, $a);
} else if (strncmp($a['refname'], "refs/heads/", 11) == 0) {
	rg_git_update_branch($db, $a);
} else if (strncmp($a['refname'], "refs/remotes/", 13) == 0) {
	rg_git_fatal("No action for remotes for now!");
} else {
	rg_git_fatal("Unknown refname type provided [" . $a['refname'] . "]");
}

rg_prof_end("hook-update");
rg_prof_log();
?>
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