-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathgit-hooks.gradle.kts
More file actions
31 lines (28 loc) · 921 Bytes
/
git-hooks.gradle.kts
File metadata and controls
31 lines (28 loc) · 921 Bytes
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
fun isLinuxOrMacOs(): Boolean {
val osName = System.getProperty("os.name").lowercase()
return osName.contains("linux") || osName.contains("mac os") || osName.contains("macos")
}
tasks.register<Copy>("copyGitHooks") {
description = "Copies the git hooks from scripts/git-hooks to the .git folder."
from("$rootDir/scripts/git-hooks/") {
include("**/*.sh")
rename("(.*).sh", "$1")
}
into("$rootDir/.git/hooks")
onlyIf { isLinuxOrMacOs() }
}
tasks.register<Exec>("installGitHooks") {
description = "Installs the git hooks from scripts/git-hooks."
group = "git hooks"
workingDir(rootDir)
commandLine("chmod")
args("-R", "+x", ".git/hooks/")
dependsOn("copyGitHooks")
onlyIf { isLinuxOrMacOs() }
doLast {
logger.info("Git hooks installed successfully.")
}
}
afterEvaluate {
tasks.findByName("clean")?.dependsOn("installGitHooks")
}