diff --git a/app/build.gradle b/app/build.gradle index 20edda6..dc75b57 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -35,6 +35,17 @@ android { } } +// https://gist.github.com/KenVanHoeylandt/c7a928426bce83ffab400ab1fd99054a?permalink_comment_id=4032669#gistcomment-4032669 +tasks.register('installGitHooks', Copy) { + from new File(rootProject.rootDir, 'pre-commit') + into { new File(rootProject.rootDir, '.git/hooks') } + fileMode 0775 +} + +afterEvaluate { + preBuild.dependsOn installGitHooks +} + dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.6.1' diff --git a/pre-commit b/pre-commit new file mode 100644 index 0000000..64e77b7 --- /dev/null +++ b/pre-commit @@ -0,0 +1,21 @@ +#!/bin/sh +# ref: gist at https://gist.github.com/chadmaughan/5889802 + +# stash any unstaged changes +git stash -q --keep-index + +# run the tests with the gradle wrapper +./gradlew spotlessCheck --full-stacktrace + +# store the last exit code in a variable +RESULT=$? + +# unstash the unstashed changes +git stash pop -q + +# if [[ $RESULT != 0 ]]; then +# echo "Formatting violations detected! Please run ./gradlew spotlessApply to fix the formatting errors." +# fi + +# return the './gradlew test' exit code +exit $RESULT