Pre commit hook Add (#600)

* added commands

* command line improvements

* remove unwanted changes
This commit is contained in:
Yogesh Choudhary Paliyal
2023-06-03 13:30:17 +05:30
committed by GitHub
parent 160a67e579
commit 065378adfc
4 changed files with 29 additions and 0 deletions

View File

@@ -54,3 +54,11 @@ subprojects {
//tasks.register("clean", Delete::class) {
// delete(rootProject.buildDir)
//}
// pre build gradle hook for git init on evey gradle build to reduce developer friction.
val installGitHook by tasks.register<Exec>("installGitHook") {
workingDir = rootProject.rootDir
commandLine = listOf("sh", "./githooks/git-init.sh")
}
tasks.getByPath("app:preBuild").dependsOn(installGitHook)

5
githooks/git-init.sh Executable file
View File

@@ -0,0 +1,5 @@
#!/bin/sh
echo "Setting Git hooks"
chmod -R +x ./githooks/
git config core.hooksPath ./githooks/

16
githooks/pre-commit Executable file
View File

@@ -0,0 +1,16 @@
#!/bin/sh
set -e
echo "*******************************"
echo "Running git pre-commit hook"
echo "*******************************"
# Run Spotless
./gradlew spotlessApply
./gradlew spotlessKotlinApply
# Check if lint found any errors
if [[ $? -ne 0 ]]; then
echo "Spotless found some errors. Please fix them before committing."
exit 1
fi

0
gradlew vendored Normal file → Executable file
View File