@@ -72,28 +72,29 @@ ext {
7272
7373 javadocMemberLevel = JavadocMemberLevel . PROTECTED
7474
75- // The local git repository, typically in the .git directory, but not for worktrees.
75+ // Path to git hooks for this checkout (works for normal repos, worktrees, and submodules) .
7676 // This value is always overwritten, but Gradle needs the variable to be initialized.
77- localRepo = " .git"
77+ localHooksDir = " .git/hooks "
7878}
7979
80- tasks. register(" setLocalRepo" , Exec ) {
81- commandLine(" git" , " worktree" , " list" )
80+ tasks. register(" setLocalHooksDir" , Exec ) {
81+ onlyIf { rootProject. file(" .git" ). exists() }
82+ commandLine(" git" , " rev-parse" , " --git-path" , " hooks" )
8283 standardOutput = new ByteArrayOutputStream ()
8384
8485 doLast {
85- String worktreeList = standardOutput. toString()
86- localRepo = worktreeList. substring(0 , worktreeList. indexOf(" " )) + " /.git"
86+ localHooksDir = standardOutput. toString(). trim()
8787 }
8888}
8989
9090// No group so it does not show up in the output of `gradlew tasks`
9191tasks. register(" installGitHooks" , Copy ) {
92- dependsOn(" setLocalRepo" )
93- description = " Copies git hooks to .git directory"
92+ onlyIf { rootProject. file(" .git" ). exists() }
93+ dependsOn(" setLocalHooksDir" )
94+ description = " Copies git hooks to the local git hooks directory"
9495 from(files(" checker/bin-devel/git.post-merge" , " checker/bin-devel/git.pre-commit" ))
9596 rename(" git\\ .(.*)" , " \$ 1" )
96- into(localRepo + " /hooks " )
97+ into({ localHooksDir } )
9798}
9899subprojects { subProject ->
99100 if (subProject. name. equals(" checker" )
0 commit comments