From 60686d0fef7283267d89aaa3bae808318006de86 Mon Sep 17 00:00:00 2001 From: davotoula Date: Sat, 28 Mar 2026 16:59:01 +0100 Subject: [PATCH] fix: resolves the .git file in worktrees by reading the gitdir: pointer and using the actual git directory for hooks installation --- build.gradle | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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