diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 00000000..7b82f95f --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,34 @@ +#!/bin/bash + +log () { + printf "[\033[1;37mpre-commit\033[0m] $1\n" +} + +rustfmt +nightly --version &>/dev/null +if [ $? != 0 ]; then + log "\033[0;33mWARN\033[0m: rustfmt +nightly not found, skipping pre-commit hook" + exit 0 +fi + +files=() + +for file in $(git diff --name-only --cached); do + if [ ${file: -3} == ".rs" ]; then + rustfmt +nightly --check $file &>/dev/null + if [ $? != 0 ]; then + files+=($file) + fi + fi +done + +if [ -n "$files" ]; then + log "the following files have improper formatting:\n" + for file in "${files[@]}"; do + printf "\033[0;33m\t$file\n" + done + printf "\n\033[0m" + log "aborting commit" + exit 1 +fi + +exit 0 diff --git a/README.md b/README.md index fd2a5a74..be04187e 100644 --- a/README.md +++ b/README.md @@ -37,3 +37,11 @@ ZoKrates is released under the GNU Lesser General Public License v3. We happily welcome contributions. You can either pick an existing issue or reach out on [Gitter](https://gitter.im/ZoKrates/Lobby). Unless you explicitly state otherwise, any contribution you intentionally submit for inclusion in the work shall be licensed as above, without any additional terms or conditions. + +### Git Hooks + +You can enable zokrates git hooks locally by running: + +```sh +git config core.hooksPath .githooks +``` \ No newline at end of file