-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-hooks.gradle
33 lines (30 loc) · 980 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
33
static def isLinuxOrMacOs() {
def osName = System.getProperty('os.name').toLowerCase(Locale.ROOT)
return osName.contains('linux') || osName.contains('mac os') || osName.contains('macos')
}
task copyGitHooks(type: Copy) {
description "Copies the git hooks from ${rootDir}/hooks to the .git folder."
from("${rootDir}/hooks/") {
include '**/*.sh'
rename '(.*).sh', '$1'
}
into "${rootDir}/.git/hooks"
onlyIf { isLinuxOrMacOs() }
}
task installGitHooks(type: Exec) {
description "Installs the pre-commit git hooks from ${rootDir}/hooks."
group 'git hooks'
workingDir rootDir
commandLine 'chmod'
args '-R', '+x', '.git/hooks/'
dependsOn copyGitHooks
onlyIf { isLinuxOrMacOs() }
doLast {
println('Git hook installed successfully.')
}
}
afterEvaluate {
// We install the hook at the first occasion
tasks['clean'].dependsOn installGitHooks
tasks['assemble'].dependsOn installGitHooks
}