Skip to content

Instantly share code, notes, and snippets.

@gabrik
Created November 5, 2021 16:41
Show Gist options
  • Save gabrik/9776cfab5b81649ef1a713116fb01c70 to your computer and use it in GitHub Desktop.
Save gabrik/9776cfab5b81649ef1a713116fb01c70 to your computer and use it in GitHub Desktop.
pre-commit and pre-push hooks for Cargo
#!/bin/bash
diff=$(cargo fmt -- --check)
result=$?
if [[ ${result} -ne 0 ]] ; then
cat <<\EOF
There are some code style issues, run `cargo fmt` first.
EOF
exit 1
fi
diff=$(cargo clippy --all --all-targets)
result=$?
if [[ ${result} -ne 0 ]] ; then
cat <<\EOF
There are some code issues, please solve them first.
EOF
exit 1
fi
exit 0
diff=$(cargo check --all-targets)
result=$?
if [[ ${result} -ne 0 ]] ; then
cat <<\EOF
There are some code issues, please solve them first.
EOF
exit 1
fi
exit 0
#!/bin/bash
diff=$(cargo test)
result=$?
if [[ ${result} -ne 0 ]] ; then
cat <<\EOF
Tests are failing, solve the bugs first.
EOF
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment