Computing New Code failed - Branch 'refs/heads/master' not found in git

Hello,

We are using SonarQube 8.9 LTS and for analyzing branches, I changed the New Code definition like this:

However, after this change when I run the analysis, I get the following error in sonar-scanner output:

INFO: Computing New Code since fork with ‘refs/heads/master’
WARN: Could not find ref ‘refs/heads/master’ in refs/heads, refs/remotes, refs/remotes/upstream or refs/remotes/origin
WARN: Branch ‘refs/heads/master’ not found in git
WARN: Failed to detect fork date. No New Code will be computed.

I searched around and saw some other people asking similar questions in the past and the suggestion was to fetch master as a build step. But this feels very hacky so I wanted to know if there is another proper out of the box solution for this problem.

Software used:

  • SonarQube 8.9.8 LTS
  • TeamCity (teamcity.git.fetchAllHeads = true is set)

Hi,
The scanner will try to access the reference branch using git to be able to compute the new code in the branch being analyzed.
So either the branch name is incorrect, or it’s not available in the local clone being used in the analysis.

It looks like the problem might be the first case. The branch name is master, but it’s showing as refs/heads/master, which is git’s internal path to the reference for the master branch.
I suggest you try to analyze the master setting sonar.branch.name=master.

4 Likes

Thank you. The problem was solved by using “master” instead of “refs/heads/master”.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.