Skip to content
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

Merged
merged 7 commits into from
Mar 14, 2024
Merged

ci: add pre-commit hook #3262

merged 7 commits into from
Mar 14, 2024

Conversation

bingryan
Copy link
Contributor

Description

add git pre-commit hook

Usage

step1: install pre-commit for you local repo

just git-pre-commit

step2: auto format submitted **.rs files for your git commit xxxx

@bingryan
Copy link
Contributor Author

After several PRs, i sometimes submit some unformatted code, then get CI lint error. i think add pre-commit hook is useful for this case.

@bingryan
Copy link
Contributor Author

bingryan commented Mar 11, 2024

@casey I don't know if this is a necessary PR, I think If format and test can be performed before each commit. it will reduce some unnecessary CI time

bin/pre-commit Outdated
Comment on lines 10 to 11
cargo fmt --all
git add -- $(echo "$files" | paste -s -d " " -)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cargo fmt --all
git add -- $(echo "$files" | paste -s -d " " -)
cargo fmt --check

Copy link
Contributor Author

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.

Copy link
Collaborator

@raphjaph raphjaph left a 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,

@bingryan
Copy link
Contributor Author

only format the submitted Rust file now

@raphjaph
Copy link
Collaborator

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

Copy link
Collaborator

@raphjaph raphjaph left a 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.

@casey casey merged commit 463a2e0 into ordinals:master Mar 14, 2024
5 checks passed
popcnt1 pushed a commit to popcnt1/ord that referenced this pull request Jan 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants