From 61f5d4b172ae402ab2a9ebf594462dd5ddf4a007 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Wed, 2 May 2018 09:56:33 +0200 Subject: [PATCH] Docs: Change git hook to only look in changed files --- doc/development/setup.rst | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/doc/development/setup.rst b/doc/development/setup.rst index ede843a1ee..b262319be8 100644 --- a/doc/development/setup.rst +++ b/doc/development/setup.rst @@ -115,12 +115,19 @@ Execute the following command to run pretix' test suite (might take a couple of ``NUM`` being the number of threads you want to use. It is a good idea to put this command into your git hook ``.git/hooks/pre-commit``, -for example:: +for example, to check for any errors in any staged files when committing:: - #!/bin/sh + #!/bin/bash cd $GIT_DIR/../src - flake8 . || exit 1 - isort -q -rc -c . || exit 1 + export GIT_WORK_TREE=../ + export GIT_DIR=../.git + source ../env/bin/activate # Adjust to however you activate your virtual environment + for file in $(git diff --cached --name-only | grep -E '\.py$') + do + git show ":$file" | flake8 - --stdin-display-name="$file" || exit 1 # we only want to lint the staged changes, not any un-staged changes + git show ":$file" | isort -df --check-only - | grep ERROR && exit 1 + done + This keeps you from accidentally creating commits violating the style guide.