diff --git a/build.gradle b/build.gradle index a551d4bb6..a94673618 100644 --- a/build.gradle +++ b/build.gradle @@ -191,7 +191,7 @@ spotless { // pre-commit spotless check script tasks.register('updateGitHooks', Copy) { - from './scripts/pre-commit' - into './.git/hooks' + from 'scripts/pre-commit' + into '.git/hooks' } compileJava.dependsOn updateGitHooks diff --git a/scripts/pre-commit b/scripts/pre-commit old mode 100644 new mode 100755 index 7b75d9c86..7dee15dbd --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -1,10 +1,13 @@ -#!/bin/bash -echo "Running spotless check" -./gradlew spotlessCheck -if [ \$? -eq 0 ] -then - echo "Spotless check succeed" -else - echo "Spotless check failed" >&2 -exit 1 -fi +#!/bin/sh + +targetFiles=$(git diff --staged --name-only) + +echo "Apply Spotless.." +./gradlew spotlessApply + +# Add files to stage spotless applied +for file in $targetFiles; do + if test -f "$file"; then + git add $file + fi +done