From 4bbc5070e8f225946bb3afdf4f690442dd8b4649 Mon Sep 17 00:00:00 2001 From: Zykino Date: Mon, 31 Aug 2020 19:06:50 +0200 Subject: [PATCH] Add instruction for pre-commit hook --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index c7da9e1..6fe8b36 100644 --- a/README.md +++ b/README.md @@ -17,3 +17,23 @@ Launch tests with ```sh python3 -m unittest ``` + +# git hook +To start tests automatically you can create a `pre-commit` file in `.git/hooks/` with the following content: +```sh +#!/usr/bin/env bash + +# run tests +python3 -m unittest discover . --failfast +# unittest exists with 0 if all tests passed, 1 otherwise. +tests_failed=$? +if [ ${tests_failed} -eq 1 ]; then + echo "Tests failed. Aborting commit" + exit 1 +fi + +exit 0 +``` +The hook should have execution right, `chmod 775 .git/hooks/pre-commit`. + +Maybe we can use the example here https://gist.github.com/orenshk/6cab23fcff847d704af7f3eec22b1ba6 as pre-commit hook to also format according to PEP8.