n0mer / gradle-git-properties

Gradle plugin for `git.properties` file generation
https://plugins.gradle.org/plugin/com.gorylenko.gradle-git-properties
Apache License 2.0
323 stars 55 forks source link

Better communication of exceptions in GitDirLocator #228

Open rehevkor5 opened 1 year ago

rehevkor5 commented 1 year ago

Was experiencing a strange failure:

> Error while evaluating property 'generatedProperties' of task ':generateGitProperties'.
   > No Git repository found.

This was occurring despite a .git directory being present.

After re-running with --debug, I observed an exception like so:

java.io.FileNotFoundException: /Users/myuser/.gitconfig (Permission denied)
        at java.base/java.io.FileInputStream.open0(Native Method)
        at java.base/java.io.FileInputStream.open(FileInputStream.java:216)
        at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157)
        at gradlegitproperties.org.eclipse.jgit.util.io.SilentFileInputStream.<init>(SilentFileInputStream.java:31)
        at gradlegitproperties.org.eclipse.jgit.util.IO.readFully(IO.java:101)
        at gradlegitproperties.org.eclipse.jgit.util.IO.readFully(IO.java:48)
        at gradlegitproperties.org.eclipse.jgit.storage.file.FileBasedConfig.load(FileBasedConfig.java:127)
        at gradlegitproperties.org.eclipse.jgit.util.SystemReader.updateAll(SystemReader.java:390)
        at gradlegitproperties.org.eclipse.jgit.util.SystemReader.getUserConfig(SystemReader.java:316)
        at gradlegitproperties.org.eclipse.jgit.internal.storage.file.FileRepository.<init>(FileRepository.java:161)
        at gradlegitproperties.org.eclipse.jgit.lib.BaseRepositoryBuilder.build(BaseRepositoryBuilder.java:625)
        at gradlegitproperties.org.eclipse.jgit.api.Git.open(Git.java:93)
        at gradlegitproperties.org.eclipse.jgit.api.Git.open(Git.java:73)
        at gradlegitproperties.org.eclipse.jgit.api.Git$open.call(Unknown Source)
        at gradlegitproperties.org.ajoberstar.grgit.operation.OpenOp.call(OpenOp.groovy:46)
        at gradlegitproperties.org.ajoberstar.grgit.operation.OpenOp.call(OpenOp.groovy)
        at java_util_concurrent_Callable$call.call(Unknown Source)
        at gradlegitproperties.org.ajoberstar.grgit.internal.OpSyntax.mapOperation(OpSyntax.groovy:20)
        at gradlegitproperties.org.ajoberstar.grgit.internal.OpSyntax$mapOperation.callStatic(Unknown Source)
        at gradlegitproperties.org.ajoberstar.grgit.Grgit.open(Grgit.groovy)
        at gradlegitproperties.org.ajoberstar.grgit.Grgit$open.call(Unknown Source)
        at com.gorylenko.GitDirLocator.lookupGitDirectory(GitDirLocator.groovy:23)
        at com.gorylenko.GitDirLocator$lookupGitDirectory.call(Unknown Source)
        at com.gorylenko.GenerateGitPropertiesTask.getDotGitDirectory(GenerateGitPropertiesTask.groovy:155)
        at com.gorylenko.GenerateGitPropertiesTask.getSource(GenerateGitPropertiesTask.groovy:58)
        at com.gorylenko.GenerateGitPropertiesTask_Decorated.getSource(Unknown Source)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.gradle.api.internal.tasks.properties.bean.AbstractNestedRuntimeBeanNode$BeanPropertyValue$1$1.create(AbstractNestedRuntimeBeanNode.java:77)
        at org.gradle.internal.deprecation.DeprecationLogger.whileDisabled(DeprecationLogger.java:256)
...

(truncated Gradle call stack for brevity)

So, turns out my recent migration to a new laptop led to incorrect permissions on my ~/.gitconfig file, and this manifests as the confusing "No Git repository found." error.

So, it's easy to fix. But it looks like better exception handling inside of com.gorylenko.GitDirLocator.lookupGitDirectory would probably result in a more informative error message.