-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
ci: add pre-commit hook #3262
ci: add pre-commit hook #3262
Conversation
After several PRs, i sometimes submit some unformatted code, then get |
@casey I don't know if this is a necessary PR, I think If |
bin/pre-commit
Outdated
cargo fmt --all | ||
git add -- $(echo "$files" | paste -s -d " " -) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cargo fmt --all | |
git add -- $(echo "$files" | paste -s -d " " -) | |
cargo fmt --check |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only automatically formats the submitted rust file.
for only cargo fmt --check
, if there are unformatted files, you will need to execute cargo fmt --all
and then git add xxx
again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't want to add anything and only check formatting,
only format the submitted Rust file now |
It's not a good idea to change files in a pre-commit hook. So we only want to check things not write to any files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Made it very simple and generic for now, we can add more complex hooks later.
Description
add git
pre-commit
hookUsage
step1
: install pre-commit for you local repostep2
: auto format submitted**.rs
files for yourgit commit xxxx