execute ktlint in git pre-commit hook

This commit is contained in:
Marcos Paulo Farias
2020-02-07 00:20:29 -03:00
parent e0f86521a1
commit 5642ec70ed
2 changed files with 21 additions and 0 deletions

6
install-git-hook.gradle Normal file
View File

@ -0,0 +1,6 @@
task installGitHook(type: Copy) {
from new File(rootProject.rootDir, 'pre-commit')
into { new File(rootProject.rootDir, '.git/hooks') }
fileMode 0777
}
preBuild.dependsOn installGitHook

15
pre-commit Executable file
View File

@ -0,0 +1,15 @@
#!/bin/bash
git stash -q --keep-index
echo "Running git pre-commit hook"
./gradlew ktlint
RESULT=$?
git stash pop -q
# return 1 exit code if running checks fails
[ $RESULT -ne 0 ] && exit 1
exit 0