Skip to content

Instantly share code, notes, and snippets.

@plant99
Created March 13, 2019 18:20
Show Gist options
  • Save plant99/27d94bd95e19e288736505bdaeb648b0 to your computer and use it in GitHub Desktop.
Save plant99/27d94bd95e19e288736505bdaeb648b0 to your computer and use it in GitHub Desktop.
x = """
python -m pytest
if [ $? -eq 0 ]; then
# tests passed, proceed to prepare commit message
exit 0
else
# some tests failed, prevent from committing broken code on master
echo "Some tests failed. You are not allowed to commit broken code on master! Aborting the commit."
echo "Note: you can still commit broken code on feature branches"
exit 1
fi
"""
pre_push_file = open('./.git/hooks/pre-push', 'r')
pre_push_file_content = pre_push_file.read()
pre_push_file.close()
if x not in pre_push_file_content:
pre_push_file = open('./.git/hooks/pre-push', 'a')
pre_push_file.write(x)
pre_push_file.close()
print("Pre Commit hook for pytest added!")
else:
print("Pre Commit hook for pytest already added")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment