Skip to content

Commit 6c7c596

Browse files
authored
Merge pull request #112 from github/prcv-block-direct-pushes
add script to restrict changes on default branch to PRs
2 parents 1c070ef + fef366b commit 6c7c596

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
#
3+
# This hook restricts changes on the default branch to those made with the GUI Pull Request Merge button, or the Pull Request Merge API.
4+
#
5+
DEFAULT_BRANCH=$(git symbolic-ref HEAD)
6+
while read -r oldrev newrev refname; do
7+
if [[ "${refname}" != "${DEFAULT_BRANCH:=refs/heads/master}" ]]; then
8+
exit 0
9+
else
10+
if [[ "${GITHUB_VIA}" != 'pull request merge button' && \
11+
"${GITHUB_VIA}" != 'pull request merge api' ]]; then
12+
echo "Changes to the default branch must be made by Pull Request. Direct pushes, edits, or merges are not allowed."
13+
exit 1
14+
else
15+
exit 0
16+
fi
17+
fi
18+
done

0 commit comments

Comments
 (0)