diff --git a/build.gradle b/build.gradle index d49c130f7..ae3903522 100644 --- a/build.gradle +++ b/build.gradle @@ -62,9 +62,18 @@ subprojects { } tasks.register('installGitHook', Copy) { + def dotGit = new File(rootProject.rootDir, '.git') + def hooksDir + if (dotGit.isFile()) { + // Git worktree: .git is a file with "gitdir: " + def gitDir = new File(dotGit.text.trim().replace('gitdir: ', '')) + hooksDir = new File(gitDir, 'hooks') + } else { + hooksDir = new File(dotGit, 'hooks') + } from new File(rootProject.rootDir, '.git-hooks/pre-commit') from new File(rootProject.rootDir, '.git-hooks/pre-push') - into { new File(rootProject.rootDir, '.git/hooks') } + into { hooksDir } filePermissions { unix(0777) } } tasks.getByPath(':amethyst:preBuild').dependsOn installGitHook