Shallow clone detected but my repo is not shallow

Hey,

I need to set up sonarqube on some projects via Gitlab CI and when the job is running I got an warning :

WARN: Shallow clone detected, no blame information will be provided. You can convert to non-shallow with 'git fetch --unshallow'.
INFO: SCM Publisher 0/223 source files have been analyzed (done) | time=3ms
WARN: Missing blame information for the following files:

So it skips all files to analize :cry:

I don’t understand because on git documentation, a shallow repository will have a file .git/shallow in the repo but I don’t have this file. So it’s not a shallow clone repo.

I don’t know what to do…

Thanks,

  • SonarQube: 8.4.1
  • SonarScanner : 4.4.0.2170
  • Java 11.0.7 Alpine (64-bit)
  • Linux 4.15.0-117-generic amd64
2 Likes

Hi, it’s a shallow clone only in the GitLab runner context. If on your job script you do a ls .git/shallow, you will see something :slight_smile:

The solution to this is to force the runner to do a full clone, with the env variable GIT_DEPTH: 0. Look at the examples here.

Thanks Pierre for your help.

Indeed, when I run cat .git/shallow in the runner I got something

$ cat .git/shallow
044a4add41791259389abde2d056da4487bf9909
0c9b78c93c6cf894ad34a832f11c99588fe57583
1641ed3a25d5d737e6e31796c481d073bf7631fe
7515ce82566e6600aabe1b80cb1f7eaaca390042
fbdb8d309f8a97399b58d7eba782641dc56fd29a

I updated my .gitlab-ci.yml to add the depth variable set to 0 but I still go the same error about shallow :confused:

Here is my .gitlab-ci.yml

image: forge-registry.my-compagny.fr/it/standard-deployment-image:latest

stages:
  - analysis
  
variables:
  GIT_DEPTH: 0 # Tells git to fetch all the branches of the project, required by the analysis task

sonar:
  stage: analysis
  only:
    - test-sonar
  except:
    - tags
  when: on_success
  allow_failure: false
  variables:
    EXCLUDE: node_modules/**, reports/**
  script:
    - mkdir reports
    - dependency-check --scan .  --format "ALL"  --project "IFS WebApp Frontend" -o reports
    - sonar-scanner -Dsonar.projectKey=my-app-id -Dsonar.sources=. -Dsonar.host.url=https://sonar.development.my-compagny -Dsonar.login=XXXXXXXXXXXX -Dsonar.qualitygate.wait=true -Dsonar.exclusions="${EXCLUDE}" -Dsonar.dependencyCheck.xmlReportPath"reports/dependency-check-report.xml" -Dsonar.dependencyCheck.htmlReportPath="reports/dependency-check-report.html"

Thanks !

Please give a try to specify this variable in the job itself, not globally. Like that:

1 Like

Here is my modified job :

sonar:
  stage: analysis
  only:
    - test-sonar
  except:
    - tags
  when: on_success
  allow_failure: false
  variables:
    EXCLUDE: node_modules/**, reports/**    
    GIT_DEPTH: 0 # Tells git to fetch all the branches of the project, required by the analysis task
  script:
    - mkdir reports
    - cat .git/shallow
    - dependency-check --scan .  --format "ALL"  --project "IFS WebApp Frontend" -o reports
    - sonar-scanner -Dsonar.projectKey=ifs-webapp-frontend -Dsonar.sources=. -Dsonar.host.url=https://sonar.development.sii -Dsonar.login=cc0fc5f6a99f4a80cc488f2552d4cad12eba909d -Dsonar.qualitygate.wait=true -Dsonar.exclusions="${EXCLUDE}" -Dsonar.dependencyCheck.xmlReportPath"reports/dependency-check-report.xml" -Dsonar.dependencyCheck.htmlReportPath="reports/dependency-check-report.html"

But I still got this error, I try to change project but still the same thing :confused: Is there a way to see the GIT_DEPTH variable is used?

WARN: Shallow clone detected, no blame information will be provided. You can convert to non-shallow with 'git fetch --unshallow'.
INFO: SCM Publisher 0/223 source files have been analyzed (done) | time=3ms
WARN: Missing blame information for the following files:
WARN:   * AAAA/MyProject/Services/Expense/XXX/Interfaces/IDocReferenceObjectAPI.cs
WARN:   * AAAA/MyProject/Helpers/DateTime/DateTimeExtensions.cs
WARN:   * AAAA/MyProject/Repositories/Expense/v2/XXX/ExpenseLineRepository.cs
WARN: ...

Ok, another thing you can try is to go on your GitLab project settings > CI/CD > General pipelines and check that you use git clone and not git fetch. Make sure as well that the .gitlab-ci.yml file you changed is the one on the branch you are building (I don’t know how familiar you are with gitlab ^^)

2 Likes

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