Difference on new code after renaming file and class between MR and Main branch

Developer Edition Version 10.1 (build 73491)

Hi there,

We have found that after renaming a file and class in merge request all code is considered as new, however after merging to main only lines changed are really considered as new code.

This is causing the QG to pass for MR and fail for main branch.

Thanks for your reply

Hey there.

I’m a little confused – how does this mean that the Quality Gate passes for the merge request but fails for the main branch if more code is considered new in the context of the merge request?

Hi Colin,

Sorry for the late response.

The reason why is that old code together with new (all code considered for MR) fulfill required coverage percentage, whereas new code alone doesn’t, hence failing for main branch.

e.g. file contains existing 90 lines with 100% coverage, 10 lines are added with 0% coverage.
MR: New code considered: 100 lines - Coverage on new code 90%
Main branch: New code considered: 10 lines - Coverage on new code 0%

Please let me know if you have further questions.


Thank you! I’m surprised to here that as we should now be tracking file moves in PRs as of SonarQube 9.8 ([SONAR-13579] - Jira)

It this easily reproducible on your end, or did it happen just once?

This is not a common use case, and might have been unnoticed when the coverage in new code fulfills quality gate, so we only noticed in this case