When executing the pre-commit hook, we want to run it on the staged
files, not on the working directory, or else the buildfarm might reject
something that the precommit hook accepted because the staged version was
incorrect, but the working directory was correct. This also allows to push
valid changes while having a dirty working directory.
Details
Details
Case where there's an error in the working directory, but no errors in the staged changes:
seirl@grand-palais ~/swh-environment/swh-vault (git)-[master] % git diff diff --git a/test.py b/test.py index 982cc50..a493714 100644 --- a/test.py +++ b/test.py @@ -1,3 +1,7 @@ def respescting_pep8(arg): a = 42 + arg return a + + +def not_respecting_pep8 ( arg ) : + return(a+42)#return a+42 seirl@grand-palais ~/swh-environment/swh-vault (git)-[master] % git diff --staged diff --git a/test.py b/test.py new file mode 100644 index 0000000..982cc50 --- /dev/null +++ b/test.py @@ -0,0 +1,3 @@ +def respescting_pep8(arg): + a = 42 + arg + return a seirl@grand-palais ~/swh-environment/swh-vault (git)-[master] % make check-staged git diff -z --staged --name-only -- '*.py' \ | xargs -0 -L1 -i'{}' /bin/sh -c \ "git show ':{}' | python3 -m flake8 --stdin-display-name '{}' -"
Case where there's an error in the staged changes, but no error in the unstaged changes:
seirl@grand-palais ~/swh-environment/swh-vault (git)-[master] % git diff --staged diff --git a/test.py b/test.py new file mode 100644 index 0000000..965cd23 --- /dev/null +++ b/test.py @@ -0,0 +1,2 @@ +def not_respecting_pep8 ( arg ) : + return(a+42)#return a+42 seirl@grand-palais ~/swh-environment/swh-vault (git)-[master] % git diff diff --git a/test.py b/test.py index 965cd23..a493714 100644 --- a/test.py +++ b/test.py @@ -1,2 +1,7 @@ +def respescting_pep8(arg): + a = 42 + arg + return a + + def not_respecting_pep8 ( arg ) : return(a+42)#return a+42 seirl@grand-palais ~/swh-environment/swh-vault (git)-[master] % make check-staged git diff -z --staged --name-only -- '*.py' \ | xargs -0 -L1 -i'{}' /bin/sh -c \ "git show ':{}' | python3 -m flake8 --stdin-display-name '{}' -" test.py:1:4: E271 multiple spaces after keyword test.py:1:26: E211 whitespace before '(' test.py:1:28: E201 whitespace after '(' test.py:1:32: E202 whitespace before ')' test.py:1:34: E203 whitespace before ':' test.py:2:12: F821 undefined name 'a' test.py:2:17: E261 at least two spaces before inline comment test.py:2:17: E262 inline comment should start with '# ' ../Makefile.python:32: recipe for target 'check-staged' failed make: *** [check-staged] Error 123
Diff Detail
Diff Detail
- Repository
- rDENV Development environment
- Branch
- master
- Lint
No Linters Available - Unit
No Unit Test Coverage - Build Status
Buildable 1192 Build 1536: arc lint + arc unit
Event Timeline
Comment Actions
It'd be nice if the hook also checked stuff from bin/ that's a python script, although we should probably turn these into setuptools entry points instead.
Comment Actions
I agree that those should be just entry points, but since it's trivial to add them to check-staged I'm going to do that anyway. We can remove all that logic once we put everything as entry points.