Skip to content

Commit

Permalink
Setup pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
libliboom committed Sep 6, 2020
1 parent 1d01f4d commit 71f1d99
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Expand Up @@ -3,6 +3,7 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply from: "../ktlint.gradle"
apply from: rootProject.file('install-git-hooks.gradle')

android {
compileSdkVersion 29
Expand Down
1 change: 1 addition & 0 deletions common-utils/build.gradle
@@ -1,6 +1,7 @@
apply plugin: 'java-library'
apply plugin: 'kotlin'
apply from: "../ktlint.gradle"
apply from: rootProject.file('install-git-hooks.gradle')

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
Expand Down
1 change: 1 addition & 0 deletions epub2.0-parser/build.gradle
@@ -1,6 +1,7 @@
apply plugin: 'java-library'
apply plugin: 'kotlin'
apply from: "../ktlint.gradle"
apply from: rootProject.file('install-git-hooks.gradle')

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
Expand Down
7 changes: 7 additions & 0 deletions install-git-hooks.gradle
@@ -0,0 +1,7 @@
task installGitHooks(type: Copy) {
from new File(rootProject.rootDir, 'pre-commit')
into { new File(rootProject.rootDir, '.git/hooks') }
fileMode 0777
}

build.dependsOn installGitHooks
13 changes: 13 additions & 0 deletions pre-commit
@@ -0,0 +1,13 @@
#!/bin/sh
# From gist at https://gist.github.com/chadmaughan/5889802

echo '[git hook] executing ktlint before commit'

# run ktlint with the gradle wrapper
./gradlew ktlint --daemon

RESULT=$?

# return 1 exit code if running checks fails
[ $RESULT -ne 0 ] && exit 1
exit 0

0 comments on commit 71f1d99

Please sign in to comment.