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

Adding cargo fix to pre-commit hook #488

Merged
merged 8 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .maintain/add-precommit-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ EOF

chmod +x .git/hooks/pre-commit

echo "Hooks updated"
echo "Hooks updated"
27 changes: 27 additions & 0 deletions .maintain/add-prepush-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh

# write a whole script to pre-push hook
# NOTE: it will overwrite pre-push file!
cat > .git/hooks/pre-push <<'EOF'
#!/bin/bash

echo "Running clippy checks"

set +e

echo "Running clippy for main targets"
cargo clippy --all-features -- -W clippy::all -A clippy::style -A clippy::forget_copy -A clippy::forget_ref
ebma marked this conversation as resolved.
Show resolved Hide resolved

echo "Running clippy for all targets"
cargo clippy --all-features --all-targets -- -A clippy::all -W clippy::correctness -A clippy::forget_copy -A clippy::forget_ref

CLIPPY_EXIT_CODE=$?

set -e

if [ $CLIPPY_EXIT_CODE -ne 0 ]; then
echo "Error: Clippy checks failed" >&2
exit $CLIPPY_EXIT_CODE
fi

echo "Clippy checks successful"
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,29 @@ cargo run --bin spacewalk-standalone --release -- --dev

# Development

To ease the maintenance of proper code formatting, please consider installing the pre-commit hook contained in this
To ease the maintenance of proper code formatting and good practices, please consider installing the pre-commit hook and/or the pre-push hook contained in this
repository.
This hook runs `rustfmt` on all the changed files in a commit, to ensure that changed files are properly formatted

The pre-commit hook runs `rustfmt` on all the changed files in a commit, to ensure that changed files are properly formatted
before committing.
You can install the hook by running the following commands.

```
.maintain/add-pre-commit.sh
.maintain/add-precommit-hook.sh
```

The pre-push hool runs clippy checks that are also performed in the CI of the repository. These checks need to be successful so the push actually happens.
Otherwise, pelase run the corresponding clippy fix command or manually fix the issue.

To install the hook, run:
```
.maintain/add-prepush-hook.sh
gianfra-t marked this conversation as resolved.
Show resolved Hide resolved
```

To ignore the checks once the hook has been installed, run `git push --no-verify`.

### Note
You may need to make the hook script executable. Pleas run `chmod u+x .git/hooks/pre-push`, `chmod u+x .git/hooks/pre-commit` if necessary.

# Releases

Expand Down
Loading