Skip to content

Commit

Permalink
#223 Refactored Git hook installation task for cross-platform support
Browse files Browse the repository at this point in the history
- Removed redundant `chmod` command
- Added conditional execution for `chmod` on macOS/Linux
- Skipped `chmod` on Windows while ensuring hooks are copied correctly
- Improved logging to differentiate platform-specific behavior
  • Loading branch information
VahidGarousi committed Sep 21, 2024
1 parent c1a3273 commit 0613f4a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
19 changes: 11 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,20 @@ fun Project.registerCopyGitHooksTask() {
}

fun Project.registerInstallGitHooksTask() {
tasks.register("installGitHooks", Exec::class.java) {
tasks.register("installGitHooks") {
group = "git hooks"
description = "Installs the pre-commit git hooks from /git-hooks."
workingDir = rootDir
commandLine("chmod", "-R", "+x", ".git/hooks/")
if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine("chmod", "-R", "+x", ".git/hooks/")
}
description = "Installs the pre-commit and pre-push git hooks."
dependsOn("copyGitHooks")

doLast {
logger.info("Git hook installed successfully.")
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.")
}
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ kotlinter = "3.16.0"
#ksp = "2.0.20-1.0.25"
kotlinxImmutableCollection = "0.3.8"
androidGradlePlugin = "8.6.1"
ksp = "1.9.10-1.0.13"
konsist = "0.16.1"

ktx = "1.13.1"

Expand Down Expand Up @@ -58,7 +60,6 @@ windowsSizeClass = "1.3.0"
adaptive = "0.26.2-beta"

ktor = "2.3.12"
konsist = "0.16.1"

kotest = "5.7.2"
espressoCore = "3.6.1"
Expand Down Expand Up @@ -86,6 +87,7 @@ javax-inject = { group = "javax.inject", name = "javax.inject", version.ref = "j

coroutines = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core-jvm", version.ref = "coroutinesCore" }

konsist = { module = "com.lemonappdev:konsist", version.ref = "konsist" }
lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifeCycle" }
lifecycle-viewmodel-ktx = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-ktx", version.ref = "lifeCycleViewModelKtx" }
lifecycle-runtime-compose = { group = "androidx.lifecycle", name = "lifecycle-runtime-compose", version.ref = "lifeCycleRuntimeCompose" }
Expand All @@ -98,7 +100,6 @@ ktor-client-okhttp = { group = "io.ktor", name = "ktor-client-okhttp", version.r
ktor-json = { group = "io.ktor", name = "ktor-serialization-kotlinx-json", version.ref = "ktor" }
ktor-contentNegotiation = { group = "io.ktor", name = "ktor-client-content-negotiation", version.ref = "ktor" }
ktor-logging = { group = "io.ktor", name = "ktor-client-logging", version.ref = "ktor" }
konsist = { module = "com.lemonappdev:konsist", version.ref = "konsist" }

retrofit = { group = "com.squareup.retrofit2", name = "retrofit", version.ref = "retrofit" }
kotlinx-serialization-converter = { group = "com.jakewharton.retrofit", name = "retrofit2-kotlinx-serialization-converter", version.ref = "kotlinx-serialization-converter" }
Expand Down

0 comments on commit 0613f4a

Please sign in to comment.