Configure shared Git hooks right from your Gradle buildscript
plugins {
id 'com.github.jakemarsden.git-hooks' version 'x.x.x'
}
plugins {
id("com.github.jakemarsden.git-hooks") version "x.x.x"
}
Ensure the check
task succeeds before every commit:
gitHooks {
hooks = ['pre-commit': 'check']
}
gitHooks {
setHooks(mapOf("pre-commit" to "check"))
}
This will create a .git/hooks/pre-commit
script the next time any Gradle task runs:
#!/bin/bash
./gradlew check
The hooks directory and the Gradle command can also be changed, and a single project can have multiple hooks:
gitHooks {
hooks = [
'pre-commit': 'check',
'pre-push': 'myPrePushTask myOtherPrePushTask --info'
]
hooksDirectory = file('../.git/hooks')
gradleCommand = '/usr/bin/my-gradle-executable'
}
gitHooks {
setHooks(mapOf("pre-commit" to "check", "pre-push" to "myPrePushTask myOtherPrePushTask --info"))
setHooksDirectory(layout.projectDirectory.dir("../.git/hooks"))
setGradleCommand("/usr/bin/my-gradle-executable")
}
This will create a ../.git/hooks/pre-commit
script:
#!/bin/bash
/usr/bin/my-gradle-executable check
...and a ../.git/hooks/pre-push
script:
#!/bin/bash
/usr/bin/my-gradle-executable myPrePushTask myOtherPrePushTask --info