Merge pull request #81 from usetrmnl/git-hook-format

[ADDED] Git pre commit hook added
This commit is contained in:
Hossain Khan
2025-06-16 13:40:01 -04:00
committed by GitHub
2 changed files with 49 additions and 0 deletions
+26
View File
@@ -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
+23
View File
@@ -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