Add hooks for running linters and tests

Add the `scripts/setup-hooks.sh` script which sets the following hooks
up:
- The `post-commit` hook runs the linter after every `git commit`,
  letting you know if there are code style or rule linter offenses you
  need to fix.
- The `pre-push` hook runs the linter and the tests and block the `git
  push` if they do not succeed.
  This way you realise if everything is alright without the need of
  sending a PR.
This commit is contained in:
Ana María Martínez Gómez
2020-06-19 10:38:29 +02:00
parent 60d7c87379
commit 96ad823e35
5 changed files with 123 additions and 0 deletions

25
scripts/setup-hooks.sh Executable file
View File

@@ -0,0 +1,25 @@
#!/bin/sh
GIT_DIR=`git rev-parse --show-toplevel`
cd $GIT_DIR
# hooks may exist already (e.g. git-lfs configuration)
# If the `.git/hooks/$arg` file doesn't exist it, initialize with `#!/bin/sh`
# After that append `scripts/hooks/$arg` and ensure they can be run
create_hook() {
if [[ ! -e .git/hooks/$1 ]]; then
echo '#!/bin/sh' > .git/hooks/$1
fi
cat scripts/hooks/$1 >> .git/hooks/$1
chmod +x .git/hooks/$1
}
echo '\n#### Copying hooks into .git/hooks'
create_hook 'post-commit'
create_hook 'pre-push'
echo '\n#### Installing linter/test dependencies\n'
pip install pycodestyle
pytest-sugar
pip install https://github.com/williballenthin/vivisect/zipball/master
python setup.py develop