The SonarQube Scanner did not complete successfully: unable to open git repository (GIT WORKTREE)

which versions are you using: (SonarQube, Scanner, Plugin, and any relevant extension) Latest on both cube server and sonarscanner as of today
what are you trying to achieve: Trying to run the dotnet core sonarscanner with sonarcube server running in a local docker container
what have you tried so far to achieve this: I ran dotnet sonarscanner end

INFO: Indexing files...
INFO: Project configuration:
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 14.367s
INFO: Final Memory: 14M/147M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
ERROR: Unable to open Git repository
ERROR: Caused by: repository not found: C:\xxx\.git\worktrees\xxx
ERROR:
The SonarQube Scanner did not complete successfully
12:18:08.41  Post-processing failed. Exit code: 1

Could this be something related to git worktree?

1 Like

Hi,

You’ve indicated that you ran the end step. That’s not enough. You need to run begin, then your build, then end, as described in the docs.

 
Ann

Hi,

I did run the begin step. I just omitted it because the error occurred when i ran end.

Hi,

Please add this to your begin step and post the logs: /d:sonar.verbose=true.

 
Ann

11:21:49.289 INFO: EXECUTION FAILURE
11:21:49.289 INFO: ------------------------------------------------------------------------
11:21:49.289 INFO: Total time: 25.218s
11:21:49.427 INFO: Final Memory: 34M/554M
11:21:49.428 INFO: ------------------------------------------------------------------------
11:21:49.430 ERROR: Error during SonarQube Scanner execution
java.lang.IllegalStateException: Unable to open Git repository
        at org.sonarsource.scm.git.JGitBlameCommand.buildRepository(JGitBlameCommand.java:86)
        at org.sonarsource.scm.git.JGitBlameCommand.blame(JGitBlameCommand.java:57)
        at org.sonar.scanner.scm.ScmPublisher.publish(ScmPublisher.java:81)
        at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:365)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
        at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:126)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
        at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:73)
        at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67)
        at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
        at com.sun.proxy.$Proxy0.execute(Unknown Source)
        at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:185)
        at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:137)
        at org.sonarsource.scanner.cli.Main.execute(Main.java:111)
        at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
        at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Caused by: org.eclipse.jgit.errors.RepositoryNotFoundException: repository not found: C:\__repos\xxx\.git\worktrees\xxx
        at org.eclipse.jgit.lib.BaseRepositoryBuilder.build(BaseRepositoryBuilder.java:614)
        at org.sonarsource.scm.git.JGitBlameCommand.buildRepository(JGitBlameCommand.java:81)
        ... 22 more
Process returned exit code 1
The SonarQube Scanner did not complete successfully
11:21:49.542  Post-processing failed. Exit code: 1

By the way. Sonarscanner works for this repo if I clone it in a new folder and don´t use git worktrees. Might be good to know

Hi,

Git worktrees seems to be the key here. This is relevant:

 
Ann

OK. Good to know. I will use workarounds
No problem!

I also changed the title a little bit to refelct it

Thanks for all the help

@ganncamp Are there any suggestions on how to work around this? Worktrees are heavily used in our building/testing workflow, so this is preventing us from being able to actually see reported results.

@tyskland Were you able to find a workaround? If so, I’d appreciate if you could share it.

Hi @SakeebHossain,

As you can see in the quoted post above, the problem lies not in our software but in the underlying component, JGit. The best thing you can do is lobby them to prioritize a fix.

 
Ann

Maybe obvious, but I was revisiting this and just thought I’d share: a workaround for this is to temporarily remove the .git file in the repositories you are running sonar-scanner.

1 Like

Hi!

It’s been 3.5 years since the last post here, and the JGit issue is still languishing in limbo. I’m using the dotnet-sonarscanner v5.13.0 (4 Apr 2023) and I still cannot perform scans from git worktrees - a feature of git since 2015 (8 years ago)! Are the devs at Sonar in a position to contribute to the JGit issue and get it fixed? I have no visibility into the JIRA issue that Janos opened in 2019. A quick scan of the interwebs leads me to believe that worktrees are starting to gain popularity, so this issue may quickly become a hot topic here.

Any update on progress would be appreciated,
-Paul

1 Like