Sonarqube does not detect new-code correctly after using git rebase

This is something similar to Sonarqube does not detect New Code correctly when using git merge workflow

But I am facing the issue with git rebase. I defined new code with REFERENCE BRANCH set to master. It behaves exactly the same way as explained in the post above but with git rebase.

Steps:

  1. Create a branch from mainline: git checkout -b new_branch master
  2. Make some changes and create a commit, let’s say commit_1.
  3. Run sonar analysis on build from new_branch : we will see the new code detected as expected.
  4. Being on new_branch, run git fetch && git rebase origin/master
  5. Run sonar analysis on build from new_branch : we will not see the new code written in commit_1

I am not sure if this is the expected behavior. Can someone please confirm if they are getting the same results?

Thanks in advance.

From sonar-scanner logs, I found some abnormal lines.

SCM Publisher SCM provider for this project is: git
[07:23:41]
[Step 33/40] INFO: SCM Publisher 5 source files to be analyzed
[07:23:41]
[Step 33/40] INFO: This git repository references another local repository which is not well supported. SCM information might be missing for some files. You can avoid borrow objects from another local repository by not using --reference or --shared when cloning it.
[07:23:41]
[Step 33/40] INFO: SCM Publisher 0/5 source files have been analyzed (done) | time=177ms
[07:23:41]
[Step 33/40] WARN: Missing blame information for the following files:
.........................
[07:23:41]
[Step 33/40] WARN: This may lead to missing/broken features in SonarQube
[07:23:41]
[Step 33/40] INFO: CPD Executor 111 files had no CPD blocks
[07:23:41]
[Step 33/40] INFO: CPD Executor Calculating CPD for 791 files
[07:23:41]
[Step 33/40] INFO: CPD Executor CPD calculation finished (done) | time=286ms
[07:23:41]
[Step 33/40] INFO: Load New Code definition
[07:23:42]
[Step 33/40] INFO: Load New Code definition (done) | time=147ms
[07:23:42]
[Step 33/40] INFO: SCM writing changed lines
[07:23:42]
[Step 33/40] WARN: Could not find ref 'master' in refs/heads, refs/remotes, refs/remotes/upstream or refs/remotes/origin
[07:23:42]
[Step 33/40] INFO: SCM writing changed lines (done) | time=5ms
[07:23:42]
[Step 33/40] INFO: Analysis report generated in 336ms, dir size=20.8 MB
[07:23:43]
[Step 33/40] INFO: Analysis report compressed in 1643ms, zip size=6.8 MB
[07:23:46]
[Step 33/40] INFO: Analysis report uploaded in 2259ms

When below line is not seen, I see correct new code getting detected.

Could not find ref 'master' in refs/heads, refs/remotes, refs/remotes/upstream or refs/remotes/origin
[07:23:42]

Hi,

Are you still having problems with this?

It seems like you’ve identified some telling log lines.

Additionally,

Is your scenario that you’re making changes (rebase) locally & not checking that in? New code detection depends on your SCM data. Uncommitted changes will always mess that up.

 
Ann

Hi Ann,

The issue was the first one, It was not able to find the reference branch in any git refs. We were using Teamcity for our builds. We were able to get that working by using teamcity.git.fetchAllHeads=true

Thanks.

1 Like

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