-
-
Save reidbaker/4a223b14e465a986bcd3 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 IGNORE_HOOKS_FLAG = "ignoreMissingHooks" | |
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()) } | |
def ignore_missing_hooks = project.hasProperty(IGNORE_HOOKS_FLAG); | |
if (!missing_hooks.empty && !ignore_missing_hooks) { | |
throw new IllegalStateException( | |
"Git hooks not installed correctly! Missing these hooks: " + missing_hooks.join(", ") | |
+ "\nadd -P$IGNORE_HOOKS_FLAG to skip this check") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment