Skip to content

Commit

Permalink
add pre-commit-hook to run spotlessCheck
Browse files Browse the repository at this point in the history
Signed-off-by: VishnuSanal <[email protected]>
  • Loading branch information
VishnuSanal committed Sep 8, 2023
1 parent 3c5a2f6 commit c8b895b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
21 changes: 21 additions & 0 deletions pre-commit
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c8b895b

Please sign in to comment.