Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

Commit

Permalink
Only the RM may push to closed branches
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes committed Jan 24, 2014
1 parent 3f2060b commit 3f14736
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions hooks/pre-receive
Expand Up @@ -24,9 +24,15 @@ include 'Git/ReceiveHook.php';
include 'Git/PreReceiveHook.php';

$weKnowWhatWeAreDoing = ['dsp', 'johannes'];
// On restricted branches forced pushes are only possible by users listed in $weKnowWhatWeAreDoing
$restrictedBranches =
['php-src.git' => ['refs/heads/PHP-5.4', 'refs/heads/PHP-5.3', 'refs/heads/PHP-5.5', 'refs/heads/PHP-5.6', 'refs/heads/master'],
'playground.git' => ['refs/heads/dsp']];
// On closed branches only RMs may push
$closedBranches = [
'php-src.git' => ['refs/heads/PHP-5.3' => ['johannes']],
'playground.git' => ['refs/heads/johannes' => ['nobody']]
];

function deny($reason)
{
Expand Down Expand Up @@ -126,6 +132,22 @@ if (empty($req_paths)) {
$req_paths = ['']; // we can empty paths for trivial merge
}

if (isset($closedBranches[$repo_name])) {
$closed = array_filter(array_keys($closedBranches[$repo_name]),
function ($branch) use ($pi) {
return in_array($branch, $pi->getBranches());
});

if (count($closed)) {
$rms = $closedBranches[$repo_name];
deny("You can not push to closed branches. ".array_map(
function ($branch) use ($rms) {
return "Please contact " . implode(', ', $rms[$branch]) . " for changes to " . $branch . PHP_EOL;
},
$closed));
}
}

$restricted = [];
if (isset($restrictedBranches[$repo_name])) {
$restricted = array_filter($restrictedBranches[$repo_name],
Expand Down

0 comments on commit 3f14736

Please sign in to comment.