Skip to content

Commit d03af58

Browse files
authored
Add pre-commit hook and task to automatically install it (#408)
* Add pre-commit hook and task to install it * Update pre-commit Co-authored-by: Nicola Corti <corti.nico@gmail.com>
1 parent a920abc commit d03af58

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

build.gradle

+7
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,14 @@ allprojects {
6464
}
6565
}
6666

67+
task installGitHook(type: Copy) {
68+
from new File(rootProject.rootDir, 'pre-commit')
69+
into { new File(rootProject.rootDir, '.git/hooks') }
70+
fileMode 0777
71+
}
72+
6773
task clean(type: Delete) {
74+
dependsOn(installGitHook)
6875
delete rootProject.buildDir
6976
}
7077

pre-commit

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
echo "Running pre-commit checks..."
3+
4+
OUTPUT="/tmp/analysis-result"
5+
./gradlew detekt ktlintCheck > ${OUTPUT}
6+
EXIT_CODE=$?
7+
if [ ${EXIT_CODE} -ne 0 ]; then
8+
cat ${OUTPUT}
9+
rm ${OUTPUT}
10+
echo "*********************************************"
11+
echo " Checks Failed! "
12+
echo " Resolve found issues before committing "
13+
echo "*********************************************"
14+
exit ${EXIT_CODE}
15+
else
16+
rm ${OUTPUT}
17+
echo "*********************************************"
18+
echo " Checks Passed Successfully! "
19+
echo "*********************************************"
20+
fi

0 commit comments

Comments
 (0)