fix: resolves the .git file in worktrees by reading the gitdir: pointer and using the actual git directory for hooks installation

This commit is contained in:
davotoula
2026-03-28 16:59:01 +01:00
parent 007a0b0d43
commit 60686d0fef
+10 -1
View File
@@ -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: <path>"
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