Skip to content

Instantly share code, notes, and snippets.

@tmelz
Created February 24, 2016 22:55
Show Gist options
  • Save tmelz/65a05f6517af8d5b83ec to your computer and use it in GitHub Desktop.
Save tmelz/65a05f6517af8d5b83ec to your computer and use it in GitHub Desktop.
fail the gradle build if git-hooks don't exist
// Apply by adding the following line to your build.gradle:
// apply from: 'scripts/check_for_git_hooks.gradle'
// Comment out any hook files that aren't relevant for you.
final GIT_HOOK_DIR = ".git/hooks/"
final GIT_HOOK_FILES = [
"applypatch-msg",
"commit-msg",
"post-applypatch",
"post-checkout",
"post-commit",
"post-merge",
"post-receive",
"post-rewrite",
"post-update",
"pre-applypatch",
"pre-auto-gc",
"pre-commit",
"pre-push",
"pre-rebase",
"pre-receive",
"prepare-commit-msg",
"update"
]
def missing_hooks = GIT_HOOK_FILES.findAll { !(new File(GIT_HOOK_DIR + it).exists()) }
if (!missing_hooks.empty) {
throw new IllegalStateException(
"Git hooks not installed correctly! Missing these hooks: " + missing_hooks.join(","))
}
@tmelz
Copy link
Author

tmelz commented Feb 25, 2016

note: it'd be most convenient for devs if you just install the hooks if they aren't there! just replace the throw code with symlinking to your hooks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment