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

protect master branches except for the pecl repos against force pushes #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion hooks/pre-receive
Expand Up @@ -25,8 +25,9 @@ include 'Git/PreReceiveHook.php';

$weKnowWhatWeAreDoing = ['dsp', 'johannes', 'tyrael'];
// On restricted branches forced pushes are only possible by users listed in $weKnowWhatWeAreDoing
// the master branch is always protected except for the pecl/ repos, see below
$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'],
['php-src.git' => ['refs/heads/PHP-5.4', 'refs/heads/PHP-5.3', 'refs/heads/PHP-5.5', 'refs/heads/PHP-5.6'],
'playground.git' => ['refs/heads/dsp']];
// On closed branches only RMs may push
$closedBranches = [
Expand Down Expand Up @@ -159,6 +160,9 @@ if (isset($restrictedBranches[$repo_name])) {
return in_array($branch, $pi->getBranches());
});
}
if (strpos($repo_name, 'pecl/') !== 0 && in_array('refs/heads/master', $pi->getBranches())) {
$restricted[] = 'refs/heads/master';
}

if (count($restricted) > 0 && $pi->isForced() && !in_array($user, $weKnowWhatWeAreDoing)) {
deny("You are not allowed to overwrite commits on " . implode(', ', $restricted));
Expand Down