diff --git a/.maintain/add-precommit-hook.sh b/.maintain/add-precommit-hook.sh index c34c293d3..d1efeba40 100755 --- a/.maintain/add-precommit-hook.sh +++ b/.maintain/add-precommit-hook.sh @@ -33,4 +33,4 @@ EOF chmod +x .git/hooks/pre-commit -echo "Hooks updated" +echo "Hooks updated" \ No newline at end of file diff --git a/.maintain/add-prepush-hook.sh b/.maintain/add-prepush-hook.sh new file mode 100755 index 000000000..1ac90c730 --- /dev/null +++ b/.maintain/add-prepush-hook.sh @@ -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" diff --git a/README.md b/README.md index 9a0eb4179..e5b410e36 100644 --- a/README.md +++ b/README.md @@ -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