Created
February 24, 2016 22:55
-
-
Save tmelz/65a05f6517af8d5b83ec to your computer and use it in GitHub Desktop.
fail the gradle build if git-hooks don't exist
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
// 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(",")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.