diff --git a/build.gradle.kts b/build.gradle.kts index 48485647..86be2970 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -93,15 +93,14 @@ tasks.register("updateGitHooks") { from("scripts/pre-commit.sh") into(".git/hooks") rename("pre-commit.sh", "pre-commit") -} - -tasks.register("makeGitHooksExecutable") { - commandLine("chmod", "+x", ".git/hooks/pre-commit") - dependsOn("updateGitHooks") + doLast { + val preCommitHook = file(".git/hooks/pre-commit") + preCommitHook.setExecutable(true, false) + } } tasks.compileJava { - dependsOn("makeGitHooksExecutable") + dependsOn("updateGitHooks") } tasks.register("projectTest") { diff --git a/scripts/pre-commit.sh b/scripts/pre-commit.sh index 3a0a3cbd..3588efd5 100755 --- a/scripts/pre-commit.sh +++ b/scripts/pre-commit.sh @@ -7,7 +7,12 @@ stagedFiles=$(git diff --staged --name-only) # Part 2 echo "Running spotlessApply. Formatting code..." -cd "$PROJECT_ROOT" && ./gradlew spotlessApply + +if [ "$OS" = "Windows_NT" ]; then + cd "$PROJECT_ROOT" && ./gradlew.bat spotlessApply +else + cd "$PROJECT_ROOT" && ./gradlew spotlessApply +fi # Checking the exit status if [ $? -ne 0 ]; then