Last active
April 19, 2024 22:32
-
-
Save R1j1t/933cbf34e0054a4dfbcacb9fc5ed6206 to your computer and use it in GitHub Desktop.
Pre-commit hook for python repo: Instead of getting to know whether any lint checks failed in CI, I created this pre-commit hook in git for my python repo. Git Hooks is a powerful utility. You read from the official documentation: https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks. Please ⭑ this Gist if you find it useful! Feel free to co…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# This is a pre-commit hook for python. It checks if black is passed and then if flake8 is passed. | |
# Feel free to share your updates. It will help use these git feature! | |
if black . --check; then | |
echo "Everything is all right in black" | |
else | |
echo "" | |
echo "Auto correcting with black" | |
echo "" | |
black . | |
echo "" | |
echo "" | |
echo "Error in above files removed. plese try commit again" | |
exit 1 | |
fi | |
fs=$(flake8 . --count --exit-zero --statistics) | |
echo $fs | |
# echo ${fs:${#f2}-1:${#fs}} | |
if [ "${fs:${#f2}-1:${#fs}}" = "0" ]; then | |
echo "Everything all right flake8" | |
else | |
echo "flake8 issue found" | |
echo run flake8 . --count --exit-zero --statistics | |
echo thanks to git hooks | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment