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 / pre-commit (0293e0d3ec79589b729b1c61d1581de650d0a025) (1,176B) (mode 100755) [raw]
#!/usr/bin/php
<?php
// This is called by 'pre-commit' hook
// Inspired by pre-commit.sample in git package

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

$_start = microtime(TRUE);

$rg_log_sid = getenv('ROCKETGIT_LOG_SID');

$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 . "/git.inc.php");

rg_log_set_file($rg_log_dir . "/hook_pre-commit.log");

$repo_path = getenv("ROCKETGIT_REPO_PATH");

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

umask(0077);


if (rg_git_rev_ok("HEAD") !== FALSE)
	$against = $rg_git_empty;
else
	$against = "HEAD";

// TODO: Here we can deny non ascii file names
// git diff --cached --name-only --diff-filter=A -z $against | LC_ALL=C tr -d '[ -~]\0')
// I think we can do it already with path rights. check.


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

?>
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