Last active
March 9, 2025 14:21
-
-
Save cristiandelahooz/7ce3e873cbc892e014c7e8845381cbda to your computer and use it in GitHub Desktop.
pre-commit-gradle-spotless
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task addGitHooks { | |
doLast { | |
def gitHooksDir = '../.git/hooks' | |
def preCommitHook = file('../.scripts/pre-commit') // Archivo de hook personalizado | |
// Verifica si el directorio .git/hooks existe | |
if (file(gitHooksDir).exists()) { | |
// Copia el script del hook al directorio .git/hooks | |
copy { | |
from preCommitHook | |
into gitHooksDir | |
rename { "pre-commit" } | |
fileMode 0755 // Establece permisos de ejecución | |
} | |
println "Git pre-commit hook added." | |
} else { | |
throw new GradleException("Git hooks directory (.git/hooks) not found.") | |
} | |
} | |
} | |
build.dependsOn addGitHooks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment