Last active
April 27, 2021 22:41
-
-
Save LevitatingBusinessMan/e0c18876ff67730a928ca6cb83caf8df to your computer and use it in GitHub Desktop.
Hook I am using on uutils/coreutils. Just place as .git/hooks/pre-commit and make it executable.
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 | |
CARGO_VER=1.40.0 | |
STAGED=$(git diff --name-only --cached | grep '.*\.rs') | |
PREV_DEFAULT_VERSION=$(rustup show | grep default | head -n1 | sed 's/(default)//') | |
rustup default $CARGO_VER-x86_64-unknown-linux-gnu | |
function abort() { | |
rustup default $PREV_DEFAULT_VERSION; exit 1 | |
} | |
cargo check || { | |
echo -e "\e[31m\nCargo check failed\e[0m" ; abort | |
} | |
if ! [ "$STAGED" = '' ]; then | |
rustfmt --check $STAGED || { | |
echo -e "\e[31m\nPlease run rusftmt on all staged files before committing\e[0m" ; abort | |
} | |
fi | |
echo -e "Running \e[34mcargo +$CARGO_VER update\e[0m ..." | |
cargo +$CARGO_VER update || { | |
echo -e "\e[31mFailed to run cargo update (do you have the $CARGO_VER toolchain installed?)\e[0m" ; abort | |
} | |
rustup default $PREV_DEFAULT_VERSION |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment