-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pre-commit git hook & bootstrap script (#233)
Add pre-commit git hook & bootstrap script
- Loading branch information
Showing
5 changed files
with
74 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/sh | ||
|
||
export PATH=$PATH:$HOME/.cargo/bin | ||
|
||
rustfmt --version &>/dev/null | ||
if [ $? != 0 ]; then | ||
printf "[pre_commit] [ERROR] \"rustfmt\" not available. \n" | ||
printf "[pre_commit] [ERROR] rustfmt can be installed via - \n" | ||
printf "[pre_commit] $ rustup component add rustfmt \n" | ||
exit 1 | ||
fi | ||
|
||
|
||
problem_files=() | ||
|
||
# first collect all the files that need reformatting | ||
for file in $(git diff --name-only --cached); do | ||
if [ ${file: -3} == ".rs" ]; then | ||
rustfmt --check $file | ||
if [ $? != 0 ]; then | ||
problem_files+=($file) | ||
fi | ||
fi | ||
done | ||
|
||
if [ ${#problem_files[@]} != 0 ]; then | ||
printf "[pre_commit] [ERROR] Plaese format the files via -\n" | ||
printf "[pre_commit] $ cargo fmt --all \n" | ||
printf "[pre_commit] [ERROR] If you want to keep your format with special reason, \n" | ||
printf "[pre_commit] [ERROR] you can use this macro. \n" | ||
printf "[pre_commit] #[rustfmt::skip] \n" | ||
exit 1 | ||
fi | ||
|
||
printf "[pre_commit] [SUCCESS] rustfmt ok \n" | ||
|
||
exit 0 |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env bash | ||
|
||
# The script help you set up your develop envirnment | ||
|
||
# Setup git hooks | ||
cp .hooks/* .git/hooks | ||
|
||
# Install nightly Rust | ||
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=nightly -y | ||
|
||
# Install wasm toolchain | ||
rustup target add wasm32-unknown-unknown | ||
|
||
# Install rustfmt for coding style checking | ||
rustup component add rustfmt --toolchain nightly | ||
|
||
# TODO: help other developers with different platform | ||
sudo apt-get -y update | ||
sudo apt-get install -y cmake pkg-config libssl-dev |