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 (95e40c68870504bbf30f449466c04cc9ebf8183f) (2,455B) (mode 100755) [raw]
#!/usr/bin/php
<?php
// This is called by 'update' hook
// Inspired by upate.sample in git package
error_reporting(E_ALL);
ini_set("track_errors", "On");

$_start = microtime(TRUE);

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

$INC = dirname(__FILE__) . "/../inc";
require_once($INC . "/util.inc.php");
require_once($INC . "/log.inc.php");
require_once($INC . "/db.inc.php");
require_once($INC . "/repo.inc.php");

rg_log_set_file("/tmp/rg_hook_update.log");

rg_log("Start: euid=" . posix_geteuid() . "...");
rg_log("_SERVER: " . print_r($_SERVER, TRUE));

umask(0022);

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

if ((empty($refname) || empty($old_rev) || empty($new_rev)) {
	echo "rg: Invalid parameters!\n";
	exit(1);
}

if (strcmp($rg_repo_zero, $new_rev) == 0)
	$new_rev_type = "delete";
else
	$new_rev_type = rg_git_type($new_rev);
rg_log("new_reg_type=$new_reg_type.");

if (strcmp($new_rev_type, "commit") == 0) {
	if (strncmp($refname, "refs/tags/", 10) == 0) {
		// This is an not annoted tag - we can reject it
		rg_log("Un-annotated tag...");
	}

	if (strncmp($refname, "refs/heads/", 11) == 0) {
		if (strcmp($old_rev, $rg_repo_zero) == 0) {
			rg_log("Creating a branch...");
		}

		if (rg_git_ref_ok($new_ref . "^2")) {
			rg_log("Merge commit...");
		}

		if (rg_git_bad_whitespace($old_ref, $new_ref)) {
			rg_log("Bad whitespace...");
		}
	}

	// refs/remotes/*
} else if (strcmp($new_rev_type, "delete") == 0) {
	if (strncmp($refname, "refs/tags/", 10) == 0) {
		rg_log("Deleting a tag...");
	}

	if (strncmp($refname, "refs/heads/", 11) == 0) {
		rg_log("Deleting a branch...");
	}

	if (strncmp($refname, "refs/remotes/", 13) == 0) {
		rg_log("Deleting a tracking branch...");
	}
} else if (strcmp($new_rev_type, "tag") == 0) {
	if (strncmp($refname, "refs/tags/", 10) == 0) {
		rg_log("Modify tag...");
	}
} else {
	echo "rg: Invalid new rev type!\n";
	exit(1);
}


$diff = sprintf("%u", (microtime(TRUE) - $_start) * 1000);
rg_log("Took " . $diff . "ms.");

@file_put_contents($repo_path . "/rg/hook-update",
	"repo: " . $repo . " ($repo_path)"
	. "\nat: " . sprintf("%u", $_start)
	. "\nuid: " . $uid
	. "\ncmd: $refname $old_ref $new_ref"
	. "\nTook: " . $diff . "ms");

// Mark repository dirty for disk statistics and other stuff
@file_put_contents($rg_path . "/dirty", "");
?>
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