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

Spotless fails with an exception if the project is checked out using the git worktree functionality #75

Closed
cobexer opened this issue Jan 18, 2017 · 11 comments
Labels

Comments

@cobexer
Copy link
Contributor

cobexer commented Jan 18, 2017

There is a RFE filed for JGit at https://bugs.eclipse.org/bugs/show_bug.cgi?id=477475

Maybe there is something that can be done in Spotless besides forcing me to either disable Spotless or making a full clone for the working tree?

Stacktrace is:

org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'gradle-test-master'.
        at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:94)
        at org.gradle.configuration.project.LifecycleProjectEvaluator.notifyAfterEvaluate(LifecycleProjectEvaluator.java:89)
        at org.gradle.configuration.project.LifecycleProjectEvaluator.doConfigure(LifecycleProjectEvaluator.java:76)
        at org.gradle.configuration.project.LifecycleProjectEvaluator.access$000(LifecycleProjectEvaluator.java:33)
        at org.gradle.configuration.project.LifecycleProjectEvaluator$1.execute(LifecycleProjectEvaluator.java:53)
        at org.gradle.configuration.project.LifecycleProjectEvaluator$1.execute(LifecycleProjectEvaluator.java:50)
        at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:61)
        at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:50)
        at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:628)
        at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:129)
        at org.gradle.execution.TaskPathProjectEvaluator.configure(TaskPathProjectEvaluator.java:35)
        at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:60)
        at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:38)
        at org.gradle.initialization.DefaultGradleLauncher$1.execute(DefaultGradleLauncher.java:161)
        at org.gradle.initialization.DefaultGradleLauncher$1.execute(DefaultGradleLauncher.java:158)
        at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56)
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:158)
        at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:119)
        at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:102)
        at org.gradle.launcher.exec.GradleBuildController.run(GradleBuildController.java:71)
        at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
        at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:41)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
        at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:75)
        at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:49)
        at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:44)
        at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:29)
        at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:47)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
        at org.gradle.util.Swapper.swap(Swapper.java:38)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:72)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
        at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:297)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
        at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
Caused by: org.eclipse.jgit.errors.NoWorkTreeException: Bare Repository has neither a working tree, nor an index
        at org.eclipse.jgit.lib.Repository.getWorkTree(Repository.java:1379)
        at com.diffplug.gradle.spotless.GitAttributesLineEndingPolicy.lambda$create$25(GitAttributesLineEndingPolicy.java:62)
        at com.diffplug.common.base.Errors$Rethrowing.lambda$wrap$11(Errors.java:342)
        at com.diffplug.common.base.Errors$Rethrowing.get(Errors.java:334)
        at com.diffplug.gradle.spotless.GitAttributesLineEndingPolicy.create(GitAttributesLineEndingPolicy.java:53)
        at com.diffplug.gradle.spotless.LineEnding.createPolicy(LineEnding.java:40)
        at com.diffplug.gradle.spotless.FormatExtension.getLineEndingPolicy(FormatExtension.java:72)
        at com.diffplug.gradle.spotless.FormatExtension.setupTask(FormatExtension.java:275)
        at com.diffplug.gradle.spotless.java.JavaExtension.setupTask(JavaExtension.java:97)
        at com.diffplug.gradle.spotless.SpotlessPlugin.createTask(SpotlessPlugin.java:71)
        at com.diffplug.gradle.spotless.SpotlessPlugin.createTasks(SpotlessPlugin.java:55)
        at com.diffplug.common.base.Errors.lambda$wrap$5(Errors.java:218)
        at com.diffplug.common.base.Errors.run(Errors.java:210)
        at com.diffplug.gradle.spotless.SpotlessPlugin.lambda$apply$33(SpotlessPlugin.java:42)
        at org.gradle.internal.event.BroadcastDispatch$ActionInvocationHandler.dispatch(BroadcastDispatch.java:93)
        at org.gradle.internal.event.BroadcastDispatch$ActionInvocationHandler.dispatch(BroadcastDispatch.java:82)
        at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:44)
        at org.gradle.internal.event.BroadcastDispatch.dispatch(BroadcastDispatch.java:79)
        at org.gradle.internal.event.BroadcastDispatch.dispatch(BroadcastDispatch.java:30)
        at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
        at com.sun.proxy.$Proxy15.afterEvaluate(Unknown Source)
        at org.gradle.configuration.project.LifecycleProjectEvaluator.notifyAfterEvaluate(LifecycleProjectEvaluator.java:82)
        ... 56 more
@nedtwigg nedtwigg added the bug label Jan 18, 2017
@nedtwigg
Copy link
Member

Even if JGit doesn't fully support worktree, I'm sure it would be possible for Spotless to workaround the issue on its own.

Here's the logic in question, which would need to manually detect when git worktree is being used. PR's welcome!

@nedtwigg
Copy link
Member

Looks like JGit 5.1 might have worktree support. TBD: https://bugs.eclipse.org/bugs/show_bug.cgi?id=477475

@nedtwigg
Copy link
Member

Didn't make it into 5.1, but it's still being worked on. https://git.eclipse.org/r/#/c/126454/

@nedtwigg nedtwigg mentioned this issue Jun 13, 2019
3 tasks
@nedtwigg
Copy link
Member

nedtwigg commented Jun 1, 2020

@laffer1
Copy link

laffer1 commented Dec 31, 2020

It appears the code is initializing a repository with a FileRepositoryBuilder and this is likely part of the problem. The FileRepositoryBuilder seems to default to bare repos.

Using the Git object could possibly workaround this issue.

Git git = Git.open( localPath );
Repository repository = git.getRepository();

@nbauernfeind
Copy link

nbauernfeind commented Aug 25, 2021

@nedtwigg Can you provide any guidance? My workflow requires worktrees and the company I work for has adopted this plugin. I'm happy to make the contribution if you can give some pointers on how I can get to an approvable pull request.

@nedtwigg
Copy link
Member

It's a limitation in JGit. If you look at the links above, you'll see the bugs.eclipse.org link where the issue has been discussed, as well as gerrit patches which implement worktree functionality. As soon as JGit supports worktree, Spotless will too. If you can get the JGit issue across the finish line, then it's done!

@nbauernfeind
Copy link

Thank you!

hakanai added a commit to hakanai/spotless that referenced this issue Oct 11, 2021
If the directory found as the git dir contains a file called `gitdir`,
attempts to resolve it to find the actual git directory.

For issue diffplug#75 or my issue diffplug#964
hakanai added a commit to hakanai/spotless that referenced this issue Oct 11, 2021
If the directory found as the git dir contains a file called `gitdir`,
attempts to resolve it to find the actual git directory.

For issue diffplug#75 or my issue diffplug#964
hakanai added a commit to hakanai/spotless that referenced this issue Oct 13, 2021
Unifies logic in `GitRatchet` and `GitAttributesLineEndings` for finding the `.git` directory, into a new `GitWorkarounds` class, so both of these can now have the same workaround code for dealing with JGit not supporting worktrees.

The actual workaround works by using `FileRepositoryBuilder` to find what it thinks is the `.git` directory, and then looking inside that to see if it contains a file called `gitdir`, which indicates the location of the true `.git` directory in the case of a git worktree.

For issue diffplug#75 or my issue diffplug#964
@nedtwigg
Copy link
Member

Thanks to a creative PR from @hakanai, this issue might be solved in plugin-gradle 5.17.0 and plugin-maven 2.17.1. Test it out and report back:

  • 🚀 means "works for me" gradle
  • 👀 means "works for me" maven

If it doesn't work, post a stacktrace.

@hakanai
Copy link
Contributor

hakanai commented Nov 2, 2021

What I have found after some more testing: for some of my work projects, the gitdir file contains a path back to the .git file, but the commondir file contains a relative file path which points to the right directory, so it seems like most of the fix was right for this project too, but I just chose the wrong file to read. :(

@nedtwigg
Copy link
Member

nedtwigg commented Feb 9, 2022

Further fixed in plugin-gradle 6.2.2 and plugin-maven 2.20.2 thanks to #1119.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants