diff --git a/.githooks/README.md b/.githooks/README.md new file mode 100644 index 0000000..ca40a4e --- /dev/null +++ b/.githooks/README.md @@ -0,0 +1,26 @@ +# Git Hooks + +This project uses Git hooks to maintain code quality. + +## Setup for new developers + +After cloning the repository, run: + +```bash +git config core.hooksPath .githooks +``` + +This will configure Git to use the hooks in the `.githooks` directory. + +## Available hooks + +### Pre-commit + +Automatically runs `./gradlew formatKotlin` before each commit and prevents commits if: +- The code fails to pass formatting checks +- The formatter modifies files that aren't included in the commit + +If your commit is rejected due to formatting issues: +1. Review the error messages +2. Add the formatted files to your commit with `git add` +3. Try committing again diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000..85fb633 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,23 @@ +#!/bin/bash + +echo "Running Kotlin formatter check..." + +# Execute the Kotlin formatting task +./gradlew formatKotlin --quiet + +# Check the exit code of the format command +status=$? +if [ $status -ne 0 ]; then + echo "❌ formatKotlin failed! Please fix formatting issues before committing." + exit 1 +fi + +# Check if there are unstaged changes after formatting +if [[ -n $(git diff --name-only --diff-filter=M) ]]; then + echo "❌ Files were modified by formatKotlin. Please add these changes to your commit." + git diff --name-only --diff-filter=M + exit 1 +fi + +echo "✅ Kotlin code formatting check passed!" +exit 0