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 (7765defeff24e4767a8bd41a96be6d173e741776) (2,433B) (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);

require_once("/etc/rocketgit/config.php");

$INC = $rg_scripts . "/inc";
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");

$a = array();

$a['uid'] = @sprintf("%u", getenv("ROCKETGIT_UID"));
$a['rights'] = getenv("ROCKETGIT_REPO_RIGHTS");
$a['repo_id'] = getenv("ROCKETGIT_REPO_ID");
$a['ip'] = getenv("ROCKETGIT_IP");
$a['namespace'] = getenv("GIT_NAMESPACE");
$a['repo_path'] = getenv("ROCKETGIT_REPO_PATH");

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

umask(0022);


$a['refname'] = @rg_git_reference($_SERVER['argv'][1]);
$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 [" . $a['refname']
		. " " . $a['old_rev'] ." " . $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($a);
} else if (strncmp($a['refname'], "refs/heads/", 11) == 0) {
	rg_git_update_branch($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'] . "]");
}

@file_put_contents($a['repo_path'] . "/rocketgit/hook-update",
	"repo: " . $a['repo_path']
	. "\nat: " . sprintf("%u", $_start)
	. "\nuid: " . $a['uid']
	. "\npara: " . $a['refname'] . " " . $a['old_rev'] . " " . $a['new_rev']
	. "\nProfiling:\n" . rg_prof_text()
	. "\n_SERVER: " . rg_array2string($_SERVER));

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