Skip to content

Commit

Permalink
#223 Disable Detekt and git hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
VahidGarousi committed Sep 21, 2024
1 parent 0613f4a commit 0b70928
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ internal fun Project.configureDetekt(extension: DetektExtension) = extension.app
md.required.set(true)
}
config.setFrom(files("$rootDir/config/detekt/detekt.yml"))
ignoreFailures = true
}
dependencies {
"detektPlugins"(libs.findLibrary("detekt-formatting").get())
Expand Down
152 changes: 76 additions & 76 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,79 +36,79 @@ subprojects {
}
}
}

configureGitHooks()
fun Project.configureGitHooks() {
registerCopyPreCommitHookTask()
registerCopyPrePushHookTask()
registerCopyGitHooksTask()
registerInstallGitHooksTask()
}

fun Project.registerCopyPreCommitHookTask() {
tasks.register("copyPreCommitHook", Copy::class.java) {
group = "git hooks"
val suffix = osSuffix()
from(file("$rootDir/git-hooks/pre-commit-$suffix.sh"))
into("$rootDir/.git/hooks")
rename("pre-commit-$suffix.sh", "pre-commit")
fileMode = "775".toInt(8)
}
}

fun Project.registerCopyPrePushHookTask() {
tasks.register("copyPrePushHook", Copy::class.java) {
group = "git hooks"
val suffix = osSuffix()
from(file("$rootDir/git-hooks/pre-push-$suffix.sh"))
into("$rootDir/.git/hooks")
rename("pre-push-$suffix.sh", "pre-push")
fileMode = "775".toInt(8)
}
}

fun Project.registerCopyGitHooksTask() {
tasks.register("copyGitHooks", Copy::class.java) {
group = "git hooks"
description = "Copies the git hooks from /git-hooks to the .git folder."
dependsOn("copyPreCommitHook", "copyPrePushHook")
}
}

fun Project.registerInstallGitHooksTask() {
tasks.register("installGitHooks") {
group = "git hooks"
description = "Installs the pre-commit and pre-push git hooks."
dependsOn("copyGitHooks")

doLast {
if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
exec {
commandLine("chmod", "-R", "+x", ".git/hooks/")
}
logger.info("Git hooks installed and made executable on macOS/Linux.")
} else {
logger.info("Git hooks copied for Windows, no need for chmod.")
}
}
}
}

fun osSuffix(): String {
return if (Os.isFamily(Os.FAMILY_WINDOWS)) {
"windows"
} else {
"macos"
}
}

tasks.register("clean", Delete::class) {
delete(layout.buildDirectory)
}

afterEvaluate {
// We install the hook at the first occasion
tasks.named("clean") {
dependsOn(":installGitHooks")
}
}
//
//configureGitHooks()
//fun Project.configureGitHooks() {
// registerCopyPreCommitHookTask()
// registerCopyPrePushHookTask()
// registerCopyGitHooksTask()
// registerInstallGitHooksTask()
//}
//
//fun Project.registerCopyPreCommitHookTask() {
// tasks.register("copyPreCommitHook", Copy::class.java) {
// group = "git hooks"
// val suffix = osSuffix()
// from(file("$rootDir/git-hooks/pre-commit-$suffix.sh"))
// into("$rootDir/.git/hooks")
// rename("pre-commit-$suffix.sh", "pre-commit")
// fileMode = "775".toInt(8)
// }
//}
//
//fun Project.registerCopyPrePushHookTask() {
// tasks.register("copyPrePushHook", Copy::class.java) {
// group = "git hooks"
// val suffix = osSuffix()
// from(file("$rootDir/git-hooks/pre-push-$suffix.sh"))
// into("$rootDir/.git/hooks")
// rename("pre-push-$suffix.sh", "pre-push")
// fileMode = "775".toInt(8)
// }
//}
//
//fun Project.registerCopyGitHooksTask() {
// tasks.register("copyGitHooks", Copy::class.java) {
// group = "git hooks"
// description = "Copies the git hooks from /git-hooks to the .git folder."
// dependsOn("copyPreCommitHook", "copyPrePushHook")
// }
//}
//
//fun Project.registerInstallGitHooksTask() {
// tasks.register("installGitHooks") {
// group = "git hooks"
// description = "Installs the pre-commit and pre-push git hooks."
// dependsOn("copyGitHooks")
//
// doLast {
// if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
// exec {
// commandLine("chmod", "-R", "+x", ".git/hooks/")
// }
// logger.info("Git hooks installed and made executable on macOS/Linux.")
// } else {
// logger.info("Git hooks copied for Windows, no need for chmod.")
// }
// }
// }
//}
//
//fun osSuffix(): String {
// return if (Os.isFamily(Os.FAMILY_WINDOWS)) {
// "windows"
// } else {
// "macos"
// }
//}
//
//tasks.register("clean", Delete::class) {
// delete(layout.buildDirectory)
//}
//
//afterEvaluate {
// // We install the hook at the first occasion
// tasks.named("clean") {
// dependsOn(":installGitHooks")
// }
//}

0 comments on commit 0b70928

Please sign in to comment.