-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pre-commit git hook & bootstrap script #233
Add pre-commit git hook & bootstrap script #233
Conversation
yanganto
commented
Jan 8, 2020
•
edited
Loading
edited
- add pre-commit git hook
- add bootstrap script to help people setting up
- add rustfmt test in ci
- fix Should we use cargo fmt on .githook? #156
9cab8fc
to
6bbf9e2
Compare
Export #!/bin/sh
export PATH=$PATH:$HOME/.cargo/bin
rustfmt --version &>/dev/null
if [ $? != 0 ]; then
printf "[pre_commit] rustfmt not available.\n"
printf "[pre_commit] 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
# reformat the files that need it and re-stage them.
printf "[pre_commit] Plaese format the files via -\n"
printf "[pre_commit] cargo fmt --all\n"
printf "[pre_commit] If you want to keep your format with special reason,\n"
printf "[pre_commit] you can use this macro. \n"
printf "[pre_commit] #[rustfmt::skip]\n"
exit 1
fi
printf "[pre_commit] rustfmt\n"
exit 0 |
Okay, the script only do checking. |
- add pre-commit git hook - add bootstrap script to help people setting up
e9262c7
to
e856ea3
Compare
- test rustfmt before running test
e856ea3
to
50bebde
Compare
The |
Thanks for the review. |