Scanning showing success but "main branch of this project is empty"

I am having an issue when trying to run SonarCloud where it indicates there is no code, even though it is clearly visible in BitBucket Cloud. It actually passes successfully, but upon further review, it indicates “The main branch has no lines of code.” and “the main branch of this project is empty” – so it’s not actually scanning anything.

I don’t have admin over the original code repo, so I am mirroring the repository into my personal workspace to run SonarCloud on the mirrored repo.

To replicate the codebase I am doing:
git clone --mirror https://username@bitbucket.org/original-project/repo.git
cd repo.git
git push --mirror https://username@bitbucket.org/personal-project/repo.git

When I browse the newly mirrored personal-project repo in BitBucket, it shows code in the master branch – as expected. So that should be fine…

I am not using a pipeline, so just running the scan manually. From Windows command line, it runs and shows no errors. Using this command:
sonar-scanner.bat -D"sonar.organization=org-name" -D"sonar.projectKey=project-key" -D"sonar.sources=." -D"sonar.host.url=https://sonarcloud.io" -D"sonar.login=XXX"

It runs fine, I get an execution success. I’m running that command from the directly parallel with the folder of the project. When running it from within the repo directory I get errors regarding a Bare repo. So the scan appears to work fine.

Any idea why the scan works but reports no code?

Also, when I go into the project overview there is a message indicating “The main branch has no lines of code.”

And I do see a warning message in SonarCloud indicating “SCM provider autodetection failed. Please use “sonar.scm.provider” to define SCM of your project, or disable the SCM Sensor in the project settings.”

It seems you are running the scanner from a Git bare repo. You need to run it from a work tree. For example:

git clone https://username@bitbucket.org/original-project/repo.git
cd repo
sonar-scanner.bat -D"sonar.organization=org-name" -D"sonar.projectKey=project-key" -D"sonar.sources=." -D"sonar.host.url=https://sonarcloud.io" -D"sonar.login=XXX"

The code will get analyzed, you will not get the “The main branch has no lines of code”, nor the “SCM provider autodetection failed”.

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