From 0cec728b1048cf0b19832174523173895fc1428c Mon Sep 17 00:00:00 2001 From: Developer Date: Mon, 28 Jul 2025 21:28:31 -0700 Subject: [PATCH 1/2] Test formatting hook --- .githooks/pre-commit | 22 ++++++++++++++++++++++ setup-hooks.bat | 13 +++++++++++++ setup-hooks.sh | 12 ++++++++++++ src/test_formatting.rs | 5 +++++ 4 files changed, 52 insertions(+) create mode 100755 .githooks/pre-commit create mode 100644 setup-hooks.bat create mode 100755 setup-hooks.sh create mode 100644 src/test_formatting.rs diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000..0f4efa0 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,22 @@ +#!/bin/sh +# Pre-commit hook to run cargo fmt + +echo "Running cargo fmt..." + +# Check if cargo is available +if ! command -v cargo &> /dev/null; then + echo "cargo could not be found. Please install Rust." + exit 1 +fi + +# Run cargo fmt in check mode +if ! cargo fmt -- --check; then + echo "" + echo "Code formatting issues detected!" + echo "Please run 'cargo fmt' to fix formatting before committing." + echo "" + exit 1 +fi + +echo "Formatting check passed!" +exit 0 \ No newline at end of file diff --git a/setup-hooks.bat b/setup-hooks.bat new file mode 100644 index 0000000..0ebdd6a --- /dev/null +++ b/setup-hooks.bat @@ -0,0 +1,13 @@ +@echo off +REM Script to set up git hooks for the project on Windows + +echo Setting up git hooks... + +REM Configure git to use the .githooks directory +git config core.hooksPath .githooks + +echo. +echo Git hooks configured successfully! +echo The pre-commit hook will now run 'cargo fmt --check' before each commit. +echo. +echo To bypass the hook (not recommended), use: git commit --no-verify \ No newline at end of file diff --git a/setup-hooks.sh b/setup-hooks.sh new file mode 100755 index 0000000..f2f973f --- /dev/null +++ b/setup-hooks.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# Script to set up git hooks for the project + +echo "Setting up git hooks..." + +# Configure git to use the .githooks directory +git config core.hooksPath .githooks + +echo "Git hooks configured successfully!" +echo "The pre-commit hook will now run 'cargo fmt --check' before each commit." +echo "" +echo "To bypass the hook (not recommended), use: git commit --no-verify" \ No newline at end of file diff --git a/src/test_formatting.rs b/src/test_formatting.rs new file mode 100644 index 0000000..6d74c2f --- /dev/null +++ b/src/test_formatting.rs @@ -0,0 +1,5 @@ +// Test file with bad formatting +fn main() { +println!("Hello"); + println!("World"); + } \ No newline at end of file From 36710d8ef6c52700e7485441d08c9aee4a095b37 Mon Sep 17 00:00:00 2001 From: Developer Date: Mon, 28 Jul 2025 21:29:31 -0700 Subject: [PATCH 2/2] feat: Add git hooks for automatic code formatting - Added pre-commit hook that runs cargo fmt --check - Created setup scripts for both Unix and Windows platforms - Updated README with instructions for setting up git hooks - Ensures all code is properly formatted before commits Developers can set up hooks by running setup-hooks.sh (Unix) or setup-hooks.bat (Windows) --- README.md | 16 ++++++++++++++++ src/test_formatting.rs | 5 ----- 2 files changed, 16 insertions(+), 5 deletions(-) delete mode 100644 src/test_formatting.rs diff --git a/README.md b/README.md index 1179eb8..a3bb170 100644 --- a/README.md +++ b/README.md @@ -180,6 +180,22 @@ int main() { Contributions are welcome! Please feel free to open an issue or submit a pull request. +### Setting Up Git Hooks + +This project uses git hooks to ensure code quality. To set up the pre-commit hook that runs `cargo fmt`: + +**On Unix/Linux/macOS:** +```bash +./setup-hooks.sh +``` + +**On Windows:** +```cmd +setup-hooks.bat +``` + +This will configure git to run `cargo fmt --check` before each commit, ensuring all code is properly formatted. + ## License This project is licensed under the MIT License. diff --git a/src/test_formatting.rs b/src/test_formatting.rs deleted file mode 100644 index 6d74c2f..0000000 --- a/src/test_formatting.rs +++ /dev/null @@ -1,5 +0,0 @@ -// Test file with bad formatting -fn main() { -println!("Hello"); - println!("World"); - } \ No newline at end of file