Skip to content

installGitPreCommitHook task fails when using Git worktree #443

Closed
@koperagen

Description

@koperagen

So there's a problem, directory created by a worktree command doesn't have .git directory.
ChatGPT suggested this fix, and it appears to be working for me. @Jolanrensen what do you think?

val installGitPreCommitHook by tasks.creating(Copy::class) {
    doNotTrackState(/* reasonNotToTrackState = */ "Fails on TeamCity otherwise.")
    
    val gitHooksDir = File(rootProject.rootDir, ".git/hooks")

    if (gitHooksDir.exists()) {
        from(File(rootProject.rootDir, "gradle/scripts/pre-commit"))
        into(gitHooksDir)
        fileMode = 755
    } else {
        logger.lifecycle("'.git/hooks' directory not found. Skipping installGitPreCommitHook task.")
    }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions