aboutsummaryrefslogtreecommitdiff
path: root/git/template/hooks/pre-commit.sh
diff options
context:
space:
mode:
Diffstat (limited to 'git/template/hooks/pre-commit.sh')
-rw-r--r--git/template/hooks/pre-commit.sh12
1 files changed, 12 insertions, 0 deletions
diff --git a/git/template/hooks/pre-commit.sh b/git/template/hooks/pre-commit.sh
new file mode 100644
index 00000000..22e876ad
--- /dev/null
+++ b/git/template/hooks/pre-commit.sh
@@ -0,0 +1,12 @@
+# Reject a commit directly to a branch named 'master' if a branch named
+# 'develop' exists
+
+# Allow commit if it's not to master
+[ "$(git rev-parse --abbrev-ref HEAD)" = master ] || exit 0
+
+# Allow commit if there's no develop branch
+git show-ref --quiet --verify refs/heads/develop || exit 0
+
+# Throw toys
+printf >&2 'Branch develop exists, commits to master blocked\n'
+exit 1