microsoft / azure-pipelines-agent

Azure Pipelines Agent 🚀
MIT License
1.72k stars 864 forks source link

[BUG]: .git/shallow file not removed with fetchDepth: 0 #4419

Open bdovaz opened 1 year ago

bdovaz commented 1 year ago

What happened?

I am encountering a similar problem to the one this user is experiencing:

https://www.reddit.com/r/git/comments/1118tz1/fetch_unshallow_still_producing_a_shallow_result/

And that is that running the following yml:

workspace:
  clean: outputs

steps:
  - checkout: self
    clean: true
    fetchDepth: 0 # Required by Sonar
    fetchTags: false
    lfs: true
    submodules: false

I can't convert the working copy of git from shallow to unshallow correctly as the .git/shallow file is still there and SonarCloud detects it and gives me a warning:

08:03:03.513 WARN: Shallow clone detected, no blame information will be provided. You can convert to non-shallow with 'git fetch --unshallow'

The log of the checkout step pulls these commands with --unshallow:

git --config-env=http.extraheader=env_var_http.extraheader fetch --force --no-tags --prune --prune-tags --progress --no-recurse-submodules origin --unshallow +refs/heads/*:refs/remotes/origin/* +refs/pull/2993/merge:refs/remotes/pull/2993/merge

git --config-env=http.extraheader=env_var_http.extraheader fetch --force --no-tags --prune --prune-tags --progress --no-recurse-submodules origin --unshallow +398d0644a5217d132112190cc5f0cbae6c26a08a

But the .git/shallow file is not removed.

What determines that the .git/shallow file should be deleted?

Versions

3.225.0

Environment type (Please select at least one enviroment where you face this issue)

Azure DevOps Server type

dev.azure.com (formerly visualstudio.com)

Azure DevOps Server Version (if applicable)

No response

Operation system

Windows 11

Version controll system

No response

Relevant log output

No response

max-zaytsev commented 1 year ago

@bdovaz thank you for reporting this. I couldn't reproduce the problem. Can you share a minimal repro project and pipeline logs with debug mode enabled?

RustyF commented 11 months ago

I'm getting this too. My develop branch build is OK but not my release branch build. For my release branch, GitVersion is complaining about a shallow repo even though I can turn this off in the YAML settings and also explicitly set the checkout depth to 0 (and also max 2147483647) in the pipeline yaml to no effect.

RustyF commented 11 months ago

Just following up on this, I solved the problem by running these tasks immediately after the checkout to list and remove the shallow file directly:

      - task: PowerShell@2
        displayName: 'List .git folder (to look for shallow file)'
        inputs:
          targetType: 'inline'
          script: |
            Get-ChildItem .git
            Get-Content .git/shallow
          failOnStderr: true
          showWarnings: true  
          continueOnError: true

      - task: PowerShell@2
        displayName: 'Kill shallow file'
        inputs:
          targetType: 'inline'
          script: |
            Remove-Item .git/shallow
          failOnStderr: true
          showWarnings: true  
          continueOnError: true

It's like the --unshallow command wasn't able to remove the shallow file, perhaps due to a rights issue?

Incidentally, I turned on debug to see what was going on but the shallow file didn't come back and looking at the git command it didn't use the --unshallow option this time, I presume because there is nothing left behind to hint that it's shallow.

OS: Windows Server 2012 R2 Standard Agent version 2.186.1 Using GetSources 1.0.0 git version 2.30.2.windows.1

devin-lo commented 11 months ago

I was also experiencing this issue with several pipelines, and most of the time I was able to get around it with some combination of the shallow fetch / fetchDepth options that Microsoft did provide. In those cases, the end result is not having any flag related to shallow or unshallow. That's how we managed to get the full blame for SonarQube analysis.

However, for one of the pipelines, doing any of those combinations simply didn't work. @RustyF 's workaround helped to fix the issue one time, but then I re-did the pipeline yaml commit and for some reason it made the --unshallow totally disappear (and caused the PowerShell task to fail).

If this bug could be fixed so that having the unshallow does its job properly, that would save a lot of headache and hours of troubleshooting.

OS: Linux X64 Agent version 3.227.1 Using GetSources 1.0.0 git version 2.25.1

in-fke commented 7 months ago

Adding "same here", fetchDepth: 0 and SonarQube says:

WARN: Shallow clone detected, no blame information will be provided. You can convert to non-shallow with 'git fetch --unshallow'.

nikneem commented 3 months ago

Found this issue a little bit too late, ran into the same problem in order to get GitVersion working in my pipeline. I raised the issue on StackOverflow and came out with a work-around: https://stackoverflow.com/questions/78569253/azure-devops-task-fails-to-checkout-disabling-shallow

workspace:
  clean: all

steps:
- checkout: self
  fetchDepth: 0
  fetchTags: true
  clean: true
  displayName: Checkout and clean

The combination of Workspace clean: all and the clean: true in the checkout step seem to solve the issue.

bdovaz commented 3 months ago

@nikneem I also understand that it is still a bug because if in order to change the fetchDepth of a previous clone with that workaround we need to do a clean: all it is a big inconvenience and above all, it is not even documented....

I don't know which user has Alvin Zhao on GitHub, because I would like him to give us an answer at least to see if they intend to fix this problem or not.