Skip to content

Commit

Permalink
Update build.gradle
Browse files Browse the repository at this point in the history
  • Loading branch information
watcharapong committed Feb 17, 2024
1 parent e52af37 commit cee9761
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit cee9761

Please sign in to comment.