-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgithooks.gradle
53 lines (42 loc) · 1.34 KB
/
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// https://emmanuelkehinde.io/setting-up-git-pre-commit-pre-push-hook-for-ktlint-check/
import org.apache.tools.ant.taskdefs.condition.Os
static def osSuffix() {
def suffix = "macos"
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
suffix = "windows"
}
return suffix
}
task copyPreCommitHook(type: Copy) {
group 'git hooks'
def suffix = osSuffix()
from new File(rootProject.rootDir, "git-hooks/pre-commit-${suffix}.sh")
into { new File(rootProject.rootDir, '.git/hooks') }
rename("pre-commit-${suffix}.sh", 'pre-commit')
fileMode 0775
}
task copyPrePushHook(type: Copy) {
group 'git hooks'
def suffix = osSuffix()
from new File(rootProject.rootDir, "git-hooks/pre-push-${suffix}.sh")
into { new File(rootProject.rootDir, '.git/hooks') }
rename("pre-push-${suffix}.sh", 'pre-push')
fileMode 0775
}
task copyGitHooks(type: Copy) {
description 'Copies the git hooks from /git-hooks to the .git folder.'
group 'git hooks'
dependsOn copyPreCommitHook
dependsOn copyPrePushHook
}
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
doLast {
logger.info('Git hook installed successfully.')
}
}