/git-hooks-gradle-plugin

Configure shared Git hooks right from your Gradle buildscript

Primary LanguageJavaMIT LicenseMIT

git-hooks-gradle-plugin

Configure shared Git hooks right from your Gradle buildscript

CI Latest version Gradle plugin License

Setup

Groovy

plugins {
  id 'com.github.jakemarsden.git-hooks' version 'x.x.x'
}

Kotlin

plugins {
  id("com.github.jakemarsden.git-hooks") version "x.x.x"
}

Example usage

Simple

Ensure the check task succeeds before every commit:

Groovy

gitHooks {
  hooks = ['pre-commit': 'check']
}

Kotlin

gitHooks {
  setHooks(mapOf("pre-commit" to "check"))
}

Output

This will create a .git/hooks/pre-commit script the next time any Gradle task runs:

#!/bin/bash
./gradlew check

Full

The hooks directory and the Gradle command can also be changed, and a single project can have multiple hooks:

Groovy

gitHooks {
  hooks = [
    'pre-commit': 'check',
    'pre-push': 'myPrePushTask myOtherPrePushTask --info'
  ]
  hooksDirectory = file('../.git/hooks')
  gradleCommand = '/usr/bin/my-gradle-executable'
}

Kotlin

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")
}

Output

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