Skip to content

Instantly share code, notes, and snippets.

@cristiandelahooz
Last active March 9, 2025 14:21
Show Gist options
  • Save cristiandelahooz/7ce3e873cbc892e014c7e8845381cbda to your computer and use it in GitHub Desktop.
Save cristiandelahooz/7ce3e873cbc892e014c7e8845381cbda to your computer and use it in GitHub Desktop.
pre-commit-gradle-spotless
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