SonarLint cannot handle git blame from worktree

  • Operating system: Windows 11
  • SonarLint plugin version: 10.7.0

The solution is opened in a “git worktree”.
This results into the following error message in the log:

 [2024-07-09T13:02:19.306] [SonarLint Server RPC request executor] ERROR sonarlint - Cannot access blame info for rider.module
org.eclipse.jgit.errors.NoWorkTreeException: Bare Repository has neither a working tree, nor an index
	at org.eclipse.jgit.lib.Repository.getWorkTree(Repository.java:1582)
	at org.sonarsource.sonarlint.core.commons.util.gitblame.GitBlameUtils.blameWithFilesGitCommand(GitBlameUtils.java:52)

The message “Bare Repository has neither a working tree, nor an index” is wrong.

Hey @lg2de

This seems very related to this.

However come to think of it, I don’t quite know why SonarLint handles blame data at all. I’m sure there’s a good reason, but I don’t know what you lose if it doesn’t work. I’ll ask about that.

Hi @lg2de ,

We use JGit library to get file blame information** and as @Colin has mentioned in the references post, JGit doesn’t support the “Git Worktree” feature.
Obviously, we can’t do much on our side to fix the actual issue, but I’ve created a ticket (SLCORE-900) to handle the exception more gracefully.

Thank you for reporting this.

Best,

Vojtech

**The reason we calculate file blame information is to get a date of the latest change which is later used to determine whether a change has been done on a new code or not.

1 Like

Maybe JGit is the wrong solution for SonarLint if this bug is open for 9 years?
(Recent discussion in the bug looks like a solution in the near future…)
Anyway, you can try to optimize the exception text to be more precise.

And, please check whether this exception influences other activity of SonarLint.
I remember that I looked into the log and found the exception because I was wondering on missing issues in the file.
If git worktree is not working, identifying issues should work anyway.
I’m currently out of office, so I cannot check again.

And, please check whether this exception influences other activity of SonarLint.
I remember that I looked into the log and found the exception because I was wondering on missing issues in the file.
If git worktree is not working, identifying issues should work anyway.

Yes, that is a correct expectation. The issues should be reported even if the JGit exception is thrown. If it’s not the case, please do enable the verbose logs and attach them to this ticket.

Would be great if you can try to reproduce it yourself.
I’m back in office in august. No more details from my side until then. Please, be patient.

Thanks for the reply Lukas. It was tested on our side (Intellij with SonarLint 10.7.0.78874) and issues were reported as expected. That’s why it would be great to get our hands on the verbose logs if you can reproduce the issue on your side. (Once you get the chance, there is no rush).