Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pre-commit hook and task to automatically install it #408

Merged
merged 2 commits into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@ allprojects {
}
}

task installGitHook(type: Copy) {
from new File(rootProject.rootDir, 'pre-commit')
into { new File(rootProject.rootDir, '.git/hooks') }
fileMode 0777
}

task clean(type: Delete) {
dependsOn(installGitHook)
delete rootProject.buildDir
}

Expand Down
20 changes: 20 additions & 0 deletions pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
echo "Running pre-commit checks..."

OUTPUT="/tmp/analysis-result"
./gradlew detekt ktlintCheck > ${OUTPUT}
EXIT_CODE=$?
if [ ${EXIT_CODE} -ne 0 ]; then
cat ${OUTPUT}
rm ${OUTPUT}
echo "*********************************************"
echo " Checks Failed! "
echo " Resolve found issues before committing "
echo "*********************************************"
exit ${EXIT_CODE}
else
rm ${OUTPUT}
echo "*********************************************"
echo " Checks Passed Successfully! "
echo "*********************************************"
fi