New code with reference branch fails on incremental scan

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)

SonarQube - Developer Edition Version 9.9 (build 65466)
SonarScanner - 4.5.0.2216
Java - 11.0.3 AdoptOpenJDK (64-bit)
Build wrapper - 6.15

  • how is SonarQube deployed: zip, Docker, Helm

zip

  • what are you trying to achieve

We use Developer Edition and require code coverage gating in sonar for new code (CPP). Workflow below,
for branch X → run sonar scan (use new code compare with mainline - reference branch) → gating based on new code metric

Environment:
docker
git repo tool (git-repo - Git at Google)
Makefile build for package.

Within docker env, run sonar build wrapper to generate compile_commands.json and then run sonar scanner CLI to scan the source. For the initial run on feature branch, sonar scan reports the new code as expected with only delta changes by comparing to reference branch. For the next run (incremental change) on feature branch, it does not work as expected. It only reports current changed delta (commit) with reference branch and lacks previous change in New Code.

  • what have you tried so far to achieve this
  • set sonar.scanner.forceAnalysis=true in sonar properties to force full scan for scan
  • set sonar.scm.revision=HEAD in sonar properties
  • set sonar.newCode.referenceBranch=master in sonar.properties
  • set sonar.scm.provider=git in sonar.properties
    above options were tried individually and it did not work as such.
    Observation,
  • with another project (python and C) that uses docker env (different) and it is able to find new code for incremental scan smooth. so, we suspect that something in env is impacting sonar new code.
  • git repo tool is used in impacting workflow but the working one uses bare git.

Do not share screenshots of logs – share the text itself (bonus points for being well-formatted)!

Hey there.

By this, do you mean that the previous changed code is now a part of the Overall Code? Or has it disappeared from the branch entirely?