diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | IDEAS.md | 3 | ||||
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | git/template/hooks/pre-commit.sh | 12 |
4 files changed, 14 insertions, 3 deletions
@@ -170,6 +170,7 @@ /games/zs /git/gitconfig /git/gitconfig.m4 +/git/template/hooks/pre-commit /git/template/hooks/prepare-commit-msg /git/template/hooks/post-update /gnupg/gpg.conf @@ -32,8 +32,5 @@ Ideas * Write a ftplugin for Perl to switch between punctuation variable names and English variable names., i.e. \e on `$?` would change to `$CHILD_ERROR`, and vice-versa. -* Could probably put my pre-commit hook that bans commits to master in here; - maybe make it a bit smarter by only banning commits to master if a branch - named "develop" exists * Almost definitely going to want to try a runparts layout for Git hooks at some point @@ -264,6 +264,7 @@ GAMES = games/aaf \ games/zs GIT_TEMPLATE_HOOKS = git/template/hooks/post-update \ + git/template/hooks/pre-commit \ git/template/hooks/prepare-commit-msg all: $(BINS) git/gitconfig $(GIT_TEMPLATE_HOOKS) gnupg/gpg.conf 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 |