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

Hooks are installed during project configuration, not when installGitHooks is executed #228

Open
mabako opened this issue Apr 14, 2021 · 0 comments

Comments

@mabako
Copy link

mabako commented Apr 14, 2021

Hi,

If you use the plugin, but disable the installGitHooks task, the hooks still get executed, for example the following build.gradle would still (try to) install the git hooks:

plugins {
    id "com.gtramontina.ghooks.gradle" version "1.1.0"
}

installGitHooks.onlyIf { false }

This seems to be mostly related to https://github.com/gtramontina/ghooks.gradle/blob/master/src/main/kotlin/com/gtramontina/ghooks/GHooks.kt#L38 not having any doLast or similar action blocks.

It also seems like the tests (e.g. https://github.com/gtramontina/ghooks.gradle/blob/master/src/test/kotlin/com/gtramontina/ghooks/Standard%20Scenarios.kt#L40) don't actually trigger a Gradle build, but just load the project. Without being able to fully test it, this should probably look something like:

       project.pluginManager.apply(GHooks::class.java)
       val result = GradleRunner.create()
            .withArguments("installGitHooks")
            .withProjectDir(project.rootDir)
            .withPluginClasspath()
            .build()

        result.output shouldMatch ".*something went wrong.*".toRegexGI()
        result.output shouldMatch ".*that this is a git repository.*".toRegexGI()

This also currently means that the build succeeds if creating the symlink fails - since the installGitHooks tasks does nothing, it can't fail (and Gradle seems to ignore exceptions that happened during task configuration).

For example, running gradle assemble on this project shows no installGitHooks task is ever called:

11:37:11: Executing task 'assemble'...

Starting Gradle Daemon...
Gradle Daemon started in 1 s 370 ms

Something went wrong while installing your Git hooks.
Please make sure you have `git` installed and that this is a Git repository.
Once these conditions are satisfied, this plugin will ensure the hooks get installed.

java.util.concurrent.CompletionException: java.io.FileNotFoundException: File does not exist: ...\IdeaProjects\ghooks.gradle\.git\hooks
	at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:314)
	at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:319)
	at java.base/java.util.concurrent.CompletableFuture$UniAccept.tryFire(CompletableFuture.java:718)
	at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1705)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1692)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
Caused by: java.io.FileNotFoundException: File does not exist: ...\IdeaProjects\ghooks.gradle\.git\hooks
	at org.apache.commons.io.FileUtils.forceDelete(FileUtils.java:2396)
	at com.gtramontina.ghooks.GHooks.deleteIfExists(GHooks.kt:65)
	at com.gtramontina.ghooks.GHooks.symLinkTo(GHooks.kt:58)
	at com.gtramontina.ghooks.GHooks.access$symLinkTo(GHooks.kt:13)
	at com.gtramontina.ghooks.GHooks$apply$1$4.accept(GHooks.kt:51)
	at com.gtramontina.ghooks.GHooks$apply$1$4.accept(GHooks.kt:13)
	at java.base/java.util.concurrent.CompletableFuture$UniAccept.tryFire(CompletableFuture.java:714)
	... 8 more
> Task :compileKotlin UP-TO-DATE
> Task :compileJava NO-SOURCE
> Task :pluginDescriptors UP-TO-DATE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :inspectClassesForKotlinIC UP-TO-DATE
> Task :jar UP-TO-DATE
> Task :publishPluginJar UP-TO-DATE
> Task :javadoc NO-SOURCE
> Task :publishPluginJavaDocsJar UP-TO-DATE
> Task :assemble UP-TO-DATE

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.6.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 5s
7 actionable tasks: 7 up-to-date
11:37:19: Task execution finished 'assemble'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant