-
Notifications
You must be signed in to change notification settings - Fork 1
/
git-hooks.gradle
32 lines (28 loc) · 908 Bytes
/
git-hooks.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import static org.apache.tools.ant.taskdefs.condition.Os.*
static def isLinuxOrMacOs() {
return isFamily(FAMILY_MAC) || isFamily(FAMILY_UNIX)
}
tasks.register('copyGitHooks', Copy) {
description 'Copies the git hooks from config/git-hooks to the .git folder.'
from("${rootDir}/config/git-hooks/") {
include '**/*.sh'
rename '(.*).sh', '$1'
}
into "${rootDir}/.git/hooks"
onlyIf { isLinuxOrMacOs() }
}
tasks.register('installGitHooks', Exec) {
description 'Installs the pre-commit git hooks from config/git-hooks.'
group 'git hooks'
workingDir rootDir
commandLine 'chmod'
args '-R', '+x', '.git/hooks/'
dependsOn copyGitHooks
onlyIf { isLinuxOrMacOs() }
doLast { logger.info('Git hook installed successfully.') }
}
afterEvaluate {
// We install the hook at the first occasion
tasks['clean'].dependsOn installGitHooks
tasks['assemble'].dependsOn installGitHooks
}