Reputation: 1760
Is there any way to set up Python source checking on git server side?
Something like this (this is pre-commit
hook):
#!/bin/sh
FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -e '\.py$')
if [ -n "$FILES" ]; then
flake8 -r $FILES
fi
but on the server side(perhaps with update
hook).
Upvotes: 0
Views: 432
Reputation: 12273
You can add an update hook, that will be getting input file in format of ${ref} ${oldrev} ${newrev}
, e.g. something like refs/heads/master ddf343f635fe4440cad528e12f96f28bd50aa099 f59abbf28696389c91c2697c7db31f20cfa91d8a
.
Armed with this knowledge, you can then make a diff between those two commits, list files that are there, check them for syntax, and fail in case you don't like them. If there is an entirely new branch pushed, the ${oldrev}
will be 40 zeroes, so you'd have to probably check all the files in the new commit.
Upvotes: 2