From 065378adfc0848982a4c2831cbc619e6fba2ae91 Mon Sep 17 00:00:00 2001 From: Yogesh Choudhary Paliyal Date: Sat, 3 Jun 2023 13:30:17 +0530 Subject: [PATCH] Pre commit hook Add (#600) * added commands * command line improvements * remove unwanted changes --- build.gradle.kts | 8 ++++++++ githooks/git-init.sh | 5 +++++ githooks/pre-commit | 16 ++++++++++++++++ gradlew | 0 4 files changed, 29 insertions(+) create mode 100755 githooks/git-init.sh create mode 100755 githooks/pre-commit mode change 100644 => 100755 gradlew diff --git a/build.gradle.kts b/build.gradle.kts index 6ee1d5fb..0e370a1d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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("installGitHook") { + workingDir = rootProject.rootDir + commandLine = listOf("sh", "./githooks/git-init.sh") +} + +tasks.getByPath("app:preBuild").dependsOn(installGitHook) diff --git a/githooks/git-init.sh b/githooks/git-init.sh new file mode 100755 index 00000000..960b1692 --- /dev/null +++ b/githooks/git-init.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +echo "Setting Git hooks" +chmod -R +x ./githooks/ +git config core.hooksPath ./githooks/ diff --git a/githooks/pre-commit b/githooks/pre-commit new file mode 100755 index 00000000..3071b3a4 --- /dev/null +++ b/githooks/pre-commit @@ -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 + diff --git a/gradlew b/gradlew old mode 100644 new mode 100755