Skip to content

Commit

Permalink
Merge pull request #126 from VishnuSanal/pre-commit-hook
Browse files Browse the repository at this point in the history
Add pre-commit-hook to run spotlessCheck
  • Loading branch information
VishnuSanal committed Sep 8, 2023
2 parents 3c5a2f6 + c8b895b commit 85a1673
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 85a1673

Please sign in to comment.