diff --git a/build.gradle b/build.gradle index ef5de0c..5192191 100644 --- a/build.gradle +++ b/build.gradle @@ -17,32 +17,40 @@ spotless { } } +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.' from("${rootDir}/git-hooks/") { include '**/*.sh' - rename '(.*).sh', '$1' + rename '(.*).sh', '$1' // Removes .sh extension, adjust if necessary } into "${rootDir}/.git/hooks" - onlyIf { isLinuxOrMacOs() } -} - -static def isLinuxOrMacOs() { - def osName = System.getProperty('os.name').toLowerCase(Locale.ROOT) - return osName.contains('linux') || osName.contains('mac os') || osName.contains('macos') } task installGitHooks(type: Exec) { - description 'Installs the pre-commit.sh git hooks from /git-hooks.' + 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() } + + doFirst { + if (isLinuxOrMacOs()) { + // Unix-like OS + commandLine 'chmod', '-R', '+x', "${rootDir}/.git/hooks" + } else { + // Windows - Adjust if you have a specific command to run + // Generally, no action is needed to change permissions on Windows + commandLine 'cmd', '/c', 'echo', 'No permission change needed on Windows' + } + } + doLast { logger.info('Git hook installed successfully.') } + + dependsOn copyGitHooks } dependencies {