com karma: Deny overwriting commits on certain branches: hooks/pre-receive lib/Git/PushInformation.php

From: Date: Fri, 22 Jun 2012 17:21:22 +0000
Subject: com karma: Deny overwriting commits on certain branches: hooks/pre-receive lib/Git/PushInformation.php
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-69435@lists.php.net to get a copy of this message
Commit: abfc9e24ae4c347927259d8c4f4daabfa08407e6 Author: David Soria Parra <dsp@php.net> Fri, 22 Jun 2012 18:55:59 +0200 Parents: 9f700801135cca87ce65c61a8753d743650d6443 Branches: master Link: http://git.php.net/?p=karma.git;a=commitdiff;h=abfc9e24ae4c347927259d8c4f4daabfa08407e6 Log: Deny overwriting commits on certain branches We don't want people to be able to use force pushes on certain branches, such as PHP-5.4/PHP-5.3/master. Changed paths: M hooks/pre-receive M lib/Git/PushInformation.php Diff: diff --git a/hooks/pre-receive b/hooks/pre-receive index b23fb2c..2fcfe42 100755 --- a/hooks/pre-receive +++ b/hooks/pre-receive @@ -23,6 +23,10 @@ include 'Git/PushInformation.php'; include 'Git/ReceiveHook.php'; include 'Git/PreReceiveHook.php'; +$restrictedBranches = + ['php-src.git' => ['refs/heads/PHP-5.4', 'refs/heads/PHP-5.3', 'refs/heads/master'], + 'playground.git' => ['refs/heads/dsp']]; + function deny($reason) { fwrite(STDERR, $reason . "\n"); @@ -121,6 +125,18 @@ if (empty($req_paths)) { $req_paths = ['']; // we can empty paths for trivial merge } +$restricted = []; +if (isset($restrictedBranches[$repo_name])) { + $restricted = array_filter($restrictedBranches[$repo_name], + function ($branch) use ($pi) { + return in_array($branch, $pi->getBranches()); + }); +} + +if (count($restricted) > 0 && $pi->isForced()) { + deny("You are allowed to overwrite commits on " . implode(', ', $restricted)); +} + $prefix = sprintf('%s/', $repo_name); $avail_lines = $hook->getKarmaFile(); $req_paths = array_map(function ($x) use ($prefix) { return $prefix . $x;}, $req_paths); diff --git a/lib/Git/PushInformation.php b/lib/Git/PushInformation.php index 8b54161..1ee1351 100644 --- a/lib/Git/PushInformation.php +++ b/lib/Git/PushInformation.php @@ -92,4 +92,10 @@ class PushInformation return array_reduce($result, function($a, $b) { return $a || $b; }, false); } + + public function getBranches () { + return $this->hook->mapInput(function ($oldrev, $newrev, $refname) { + return $refname; + }); + } }

« previous php.cvs (#69435) next »