mirror of
https://github.com/usetrmnl/trmnl-android.git
synced 2026-04-29 13:35:26 -07:00
Merge pull request #81 from usetrmnl/git-hook-format
[ADDED] Git pre commit hook added
This commit is contained in:
@@ -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
|
||||
Executable
+23
@@ -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
|
||||
Reference in New Issue
Block a user