From dae57d78ef5d8e0a58e70a8a92a85e2c1e49abb1 Mon Sep 17 00:00:00 2001 From: kernelkind Date: Wed, 17 Apr 2024 13:36:20 -0400 Subject: [PATCH] Add precommit hook to suggest proper formatting Signed-off-by: kernelkind Signed-off-by: William Casarin --- README.md | 8 ++++++++ scripts/dev_setup.sh | 19 +++++++++++++++++++ scripts/pre_commit_hook.sh | 4 ++++ 3 files changed, 31 insertions(+) create mode 100755 scripts/dev_setup.sh create mode 100644 scripts/pre_commit_hook.sh diff --git a/README.md b/README.md index 10045d9..53a7515 100644 --- a/README.md +++ b/README.md @@ -75,3 +75,11 @@ The app should appear on the emulator [direnv]: https://direnv.net/ [nix]: https://nixos.org/download/ + +## Contributing +Configure the developer environment: +```bash +./scripts/dev_setup.sh +``` + +This will add the pre-commit hook to your local repository to suggest proper formatting before commits. diff --git a/scripts/dev_setup.sh b/scripts/dev_setup.sh new file mode 100755 index 0000000..d1fcc38 --- /dev/null +++ b/scripts/dev_setup.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +HOOK_SCRIPTS_DIR="scripts" +GIT_HOOKS_DIR=".git/hooks" + +# Ensure the necessary directories exist and are accessible +if [ ! -d "$HOOK_SCRIPTS_DIR" ] || [ ! -d "$GIT_HOOKS_DIR" ]; then + echo "Error: Required directories are missing. Please ensure you are in the project's root directory." + exit 1 +fi + +# Copy the pre-commit hook script +cp -p "$HOOK_SCRIPTS_DIR/pre_commit_hook.sh" "$GIT_HOOKS_DIR/pre-commit" + +# Make the hook script executable +chmod +x "$GIT_HOOKS_DIR/pre-commit" + +echo "Pre-commit hook has been set up successfully." + diff --git a/scripts/pre_commit_hook.sh b/scripts/pre_commit_hook.sh new file mode 100644 index 0000000..ffb5869 --- /dev/null +++ b/scripts/pre_commit_hook.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +cargo fmt --all --check +