aboutsummaryrefslogtreecommitdiffhomepage
path: root/CONTRIBUTING.md
diff options
context:
space:
mode:
authorGravatar Fabian Homborg <FHomborg@gmail.com>2016-05-25 16:19:20 +0200
committerGravatar Fabian Homborg <FHomborg@gmail.com>2016-05-25 16:19:20 +0200
commit2418daebf36ad8bd00f43cb50f96f6d5531c49ae (patch)
tree17179b31099c433d71911d202acabe9cdaf659ae /CONTRIBUTING.md
parent53c506f109aa9f45becd5539030f5eb4fa7eeaf4 (diff)
Add git hooks information and example
This might be useful to contributors.
Diffstat (limited to 'CONTRIBUTING.md')
-rw-r--r--CONTRIBUTING.md37
1 files changed, 37 insertions, 0 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 0052ddf7..b8aabe28 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -160,6 +160,43 @@ You'll receive an email when the tests are complete telling you whether or not a
You'll find the configuration used to control Travis in the `.travis.yml` file.
+### Git hooks
+
+Since developers sometimes forget to run the tests, it can be helpful to use git hooks (see githooks(5)) to automate it.
+
+One possibility is a pre-push hook script like this one:
+
+```sh
+#!/bin/sh
+#### A pre-push hook for the fish-shell project
+# This will run the tests when a push to master is detected, and will stop that if the tests fail
+# Save this as .git/hooks/pre-push and make it executable
+
+protected_branch='master'
+
+# Git gives us lines like "refs/heads/frombranch SOMESHA1 refs/heads/tobranch SOMESHA1"
+# We're only interested in the branches
+while read from _ to _; do
+ if [ "x$to" = "xrefs/heads/$protected_branch" ]; then
+ isprotected=1
+ fi
+done
+if [ "x$isprotected" = x1 ]; then
+ echo "Running tests before push to master"
+ make test
+ RESULT=$?
+ if [ $RESULT -ne 0 ]; then
+ echo "Tests failed for a push to master, we can't let you do that" >&2
+ exit 1
+ fi
+fi
+exit 0
+```
+
+This will check if the push is to the master branch and, if it is, will run `make test` and only allow the push if that succeeds. In some circumstances it might be advisable to circumvent it with `git push --no-verify`, but usually that should not be necessary.
+
+To install the hook, put it in .git/hooks/pre-push and make it executable.
+
## Installing the Required Tools
### Installing the Linting Tools