ajoberstar/gradle-git-publish

No such file or directory after upgrading to Gradle 5.1

chali opened this issue · 8 comments

chali commented

Summary

When I'm running gitPublishPush in a freshly cloned project without local gradle project cache (.gradle directory) and any build output directory the build fails during gitPublishCommit with this error: Exception caught during execution of add command.

When I'm running the same command again the build is successful. When I'm using Gradle 5.0 even the first build is successful.

Build file

buildscript {
    repositories {
        gradlePluginPortal()
    }

    dependencies {
        classpath "org.ajoberstar.grgit:grgit-gradle:3.0.0"
        classpath "org.ajoberstar:gradle-git-publish:2.0.0"
    }
}

apply plugin: 'java'
apply plugin: "org.ajoberstar.grgit"
apply plugin: "org.ajoberstar.git-publish"

gitPublish {

    branch = "gh-pages"

    contents {
        into("docs/") {
            from new File(project.projectDir, 'docs.txt')
        }
    }

    commitMessage = "Documentation generated"
}

gitPublishPush {
    onlyIf {
        System.env."CI"
    }
}

Here is a complete sample project: https://github.com/chali/genie

Command to reproduce

rm -Rf .gradle build && ./gradlew clean build gitPublishPush --stacktrace --info

Output

> Task :gitPublishReset
Task ':gitPublishReset' is not up-to-date because:
  Task.upToDateWhen is false.
:gitPublishReset (Thread[Execution worker for ':',5,main]) completed. Took 39.352 secs.
:gitPublishCopy (Thread[Execution worker for ':',5,main]) started.

> Task :gitPublishCopy
Deleting stale output file: /Users/mchalupa/projects/others/genie/build/gitPublish
Task ':gitPublishCopy' is not up-to-date because:
  No history is available.
:gitPublishCopy (Thread[Execution worker for ':',5,main]) completed. Took 0.01 secs.
:gitPublishCommit (Thread[Execution worker for ':',5,main]) started.

> Task :gitPublishCommit FAILED
Task ':gitPublishCommit' is not up-to-date because:
  Task.upToDateWhen is false.
:gitPublishCommit (Thread[Execution worker for ':',5,main]) completed. Took 0.016 secs.
Closing Git repo: /Users/mchalupa/projects/others/genie/.git
Closing Git publish repo: /Users/mchalupa/projects/others/genie/build/gitPublish

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':gitPublishCommit'.
> Exception caught during execution of add command

* Try:
Run with --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':gitPublishCommit'.
        ... stacktrace omitted ...
Caused by: org.eclipse.jgit.api.errors.JGitInternalException: Exception caught during execution of add command
        at org.eclipse.jgit.api.AddCommand.call(AddCommand.java:257)
        at org.eclipse.jgit.api.AddCommand.call(AddCommand.java:1)
        at java_util_concurrent_Callable$call$6.call(Unknown Source)
        at org.ajoberstar.grgit.operation.AddOp.call(AddOp.groovy:38)
        at org.ajoberstar.grgit.operation.AddOp.call(AddOp.groovy)
        at java_util_concurrent_Callable$call$5.call(Unknown Source)
        at org.ajoberstar.grgit.internal.OpSyntax.samOperation(OpSyntax.groovy:26)
        at org.ajoberstar.grgit.internal.OpSyntax$samOperation$1.callStatic(Unknown Source)
        at org.ajoberstar.grgit.internal.OpSyntax$samOperation$1.callStatic(Unknown Source)
        at org.ajoberstar.grgit.Grgit.add(Grgit.groovy)
        at org.ajoberstar.gradle.git.publish.tasks.GitPublishCommit.commit(GitPublishCommit.java:46)
        ... stacktrace omitted ...
Caused by: java.io.IOException: No such file or directory
        at org.eclipse.jgit.internal.storage.file.ObjectDirectoryInserter.newTempFile(ObjectDirectoryInserter.java:279)
        at org.eclipse.jgit.internal.storage.file.ObjectDirectoryInserter.toTemp(ObjectDirectoryInserter.java:245)
        at org.eclipse.jgit.internal.storage.file.ObjectDirectoryInserter.insert(ObjectDirectoryInserter.java:113)
        at org.eclipse.jgit.internal.storage.file.ObjectDirectoryInserter.insert(ObjectDirectoryInserter.java:142)
        at org.eclipse.jgit.internal.storage.file.ObjectDirectoryInserter.insert(ObjectDirectoryInserter.java:122)
        at org.eclipse.jgit.api.AddCommand.call(AddCommand.java:239)
        ... 79 more

It looks very similar as #35. It looks like handling of stale task output might be involved because:
Deleting stale output file: /Users/mchalupa/projects/others/genie/build/gitPublish is happening before commit and commit should use the content of deleted directory.

chali commented

@ajoberstar please, let me know if the example is sufficiently small or if I can help anyhow.

I can confirm the problem for my project.

kdubb commented

Happening for me as well. Workaround in travis seems to be to execute it twice, ignoring the result of the first execution.

Sorry for the delayed response on this and thanks for the detail in this issue.

Trying to reproduce this on my Windows 10 box, I'm hitting #68 and not getting any farther. Won't be able to get back to this right away, but if anyone else can, please let us know if you identify anything.

#68 seemed to go away on Gradle 5.3+. When upgrading your sample project to 5.4.1, everything seemed to work without a build/ or .gradle/ (on a Windows 10 box).

Could you try upgrading to the latest Gradle (and gradle-git-publish) and let me know if this is still an issue?

It works with gradle 5.4.1 for one of my projects. I'm going to try successivly for the others.

@chali has been out on vacation so I doubt he's seen this yet but he opened this after investigating some issues we were having with our project. His sample project is a simplified version of our flow. I upgraded Gradle and your plugins yesterday and it looks like our build succeeded now so this is likely fixed in the later versions of gradle as you say. I'll like @chali chime in when he's back which I believe is next week.

chali commented

I confirm that Gradle 5.4.1 doesn't have the problem. Thank you @ajoberstar for the investigation.