Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not mark entire root directory as input for git hook task #545

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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