Skip to content

Commit

Permalink
Do not mark entire root directory as input for git hook task
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafal Harabien authored and JLLeitschuh committed Feb 7, 2022
1 parent 64ac251 commit 8b3575d
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/GitHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package org.jlleitschuh.gradle.ktlint

import org.eclipse.jgit.lib.RepositoryBuilder
import org.gradle.api.DefaultTask
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.ProjectLayout
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.TaskAction
import org.intellij.lang.annotations.Language
import org.jlleitschuh.gradle.ktlint.tasks.BaseKtLintCheckTask
Expand Down Expand Up @@ -150,19 +148,13 @@ open class KtlintInstallGitHookTask @Inject constructor(
@get:Input
internal val hookName: Property<String> = objectFactory.property(String::class.java)

@get:InputDirectory
internal val projectDir: DirectoryProperty = objectFactory.directoryProperty().apply {
set(projectLayout.projectDirectory)
}
private val projectDir = projectLayout.projectDirectory.asFile

@get:InputDirectory
internal val rootDirectory: DirectoryProperty = objectFactory.directoryProperty().apply {
set(project.rootDir)
}
private val rootDirectory = project.rootDir

@TaskAction
fun installHook() {
val repo = RepositoryBuilder().findGitDir(projectDir.get().asFile).setMustExist(false).build()
val repo = RepositoryBuilder().findGitDir(projectDir).setMustExist(false).build()
if (!repo.objectDatabase.exists()) {
logger.warn("No git folder was found!")
return
Expand All @@ -181,7 +173,7 @@ open class KtlintInstallGitHookTask @Inject constructor(
gitHookFile.createNewFile()
gitHookFile.setExecutable(true)
}
val gradleRootDirPrefix = rootDirectory.get().asFile.relativeTo(repo.workTree).path
val gradleRootDirPrefix = rootDirectory.relativeTo(repo.workTree).path

if (gitHookFile.length() == 0L) {
gitHookFile.writeText(
Expand Down

0 comments on commit 8b3575d

Please sign in to comment.