Skip to content

Commit

Permalink
Adding cargo fix to pre-commit hook (#488)
Browse files Browse the repository at this point in the history
* cargo fix

* add pre push hook generator script

* pre push hook to run clippy checks

* hook description to the readme

* missing changes to the Readme

* Update README.md

Co-authored-by: Marcel Ebert <[email protected]>

* update readme, add second clippy check

---------

Co-authored-by: Marcel Ebert <[email protected]>
  • Loading branch information
gianfra-t and ebma authored Feb 28, 2024
1 parent dc69aa1 commit b9623a7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
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
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
```

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

0 comments on commit b9623a7

Please sign in to comment.