#!/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.
//
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");
rg_log_set_file("/var/log/rocketgit/hook_post-receive.log");
rg_log("Start...");
rg_log("_SERVER: " . print_r($_SERVER, TRUE));
umask(0022);
$f = @fopen("php://stdin", "r");
if ($f === FALSE) {
rg_log("Error: Cannot open stdin!");
rg_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]);
rg_log("refname=$refname old_rev=$old_rev new_rev=$new_rev.");
if (empty($refname) || empty($old_rev) || empty($new_rev))
rg_fatal("Invalid parameters [$old_rev $new_rev $refname]!");
// TODO: What we should do here?! check man githooks and git-receive-pack!
}
fclose($f);
$diff = sprintf("%u", (microtime(TRUE) - $_start) * 1000);
rg_log("Took " . $diff . "ms.");
@file_put_contents($repo_path . "/rg/hook-post-receive",
"repo: " . $repo . " ($repo_path)"
. "\nat: " . sprintf("%u", $_start)
. "\nuid: " . $uid
. "\npara: $refname $old_rev $new_rev"
. "\nTook: " . $diff . "ms"
. "\n_SERVER: " . print_r($_SERVER, TRUE));
// Mark repository dirty for disk statistics and other stuff
@file_put_contents($rg_path . "/dirty", "");
?>
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