-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgithooks.gradle
29 lines (27 loc) · 923 Bytes
/
githooks.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
// https://blog.sebastiano.dev/ooga-chaka-git-hooks-to-enforce-code-quality/
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 /git-hooks to the .git folder.'
group 'git hooks'
from("${rootDir}/analysis/git-hooks/") {
include '**/*.sh'
rename '(.*).sh', '$1'
}
into "${rootDir}/.git/hooks"
onlyIf { isLinuxOrMacOs() }
}
task installGitHooks(type: Exec) {
description 'Installs the pre-commit git hooks from /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.')
}
}