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 / post-receive (59929df86dc484c5fa33940205d9d947131ea531) (2,188B) (mode 100755) [raw]
#!/usr/bin/php
<?php

//
// post-receive hook
// TODO: This hook can be run for marking repo dirty.
// It is executed once, input is the list of SUCCESSFULLY updated ref.
// The error code is ignored.
// Useful to send mails.
// Warn: new_ref may not point to ref because of concurrent updates.
// TODO: Re-check man githooks and git-receive-pack!
//

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");

rg_prof_start("post-receive");

rg_log_set_file($rg_log_dir . "/hook_post-receive.log");

$namespace = getenv("GIT_NAMESPACE");
$repo_path = getenv("ROCKETGIT_REPO_PATH");

rg_log("Start namespace=$namespace repo_path=$repo_path");
rg_log("_SERVER: " . rg_array2string($_SERVER));

umask(0022);

$f = @fopen("php://stdin", "r");
if ($f === FALSE) {
	rg_log("Error: Cannot open stdin!");
	rg_git_fatal("Internal error!");
}
while (($set = fgets($f))) {
	$set = trim($set);
	if (empty($set))
		continue;

	$x = explode(" ", $set);
	$old_rev = @rg_git_rev($x[0]);
	$new_rev = @rg_git_rev($x[1]);
	$refname = @rg_git_reference($x[2]);
	if ($refname === FALSE)
		rg_git_fatal('Invalid reference: ' . rg_git_error() . '!');

	if (empty($refname) || empty($old_rev) || empty($new_rev))
		rg_git_fatal("Invalid parameters [$old_rev $new_rev $refname]!");

	rg_log("refname=$refname old_rev=$old_rev new_rev=$new_rev.");
}
fclose($f);

/* TODO: replace with event - do not forget to dirty the repo
$a = array(
	"op" => "push",
	"itime" => getenv("ROCKETGIT_ITIME"),
	"uid" => getenv("ROCKETGIT_LOGIN_UID"),
	"repo_id" => getenv("ROCKETGIT_REPO_ID"),
	"old_rev" => $old_rev,
	"new_rev" => $new_rev,
	"refname" => $refname,
	"elap_ms" => $_start - getenv("ROCKETGIT_ITIME"),
	"ip" => getenv("ROCKETGIT_IP")
);
rg_repo_stats_push2file($a);
*/

rg_prof_end("post-receive");
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