Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 of 4 tasks
bdovaz opened this issue Sep 5, 2023 · 8 comments
Open
1 of 4 tasks

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

bdovaz opened this issue Sep 5, 2023 · 8 comments

Comments

@bdovaz
Copy link

bdovaz commented Sep 5, 2023

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)

  • Self-Hosted
  • Microsoft Hosted
  • VMSS Pool
  • Container

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
Copy link
Contributor

@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
Copy link

RustyF commented Oct 6, 2023

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
Copy link

RustyF commented Oct 6, 2023

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
Copy link

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
Copy link

in-fke commented Jan 29, 2024

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
Copy link

nikneem commented Jun 4, 2024

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
Copy link
Author

bdovaz commented Jun 4, 2024

@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.

@elifry
Copy link

elifry commented Oct 23, 2024

Can confirm that I have this issue also - presented initially as gitversion thinking the Azure clone was shallow when it clearly was not shallow and was verified as such with steps prior to running gitversion.

Similar to this: https://stackoverflow.com/questions/78569253/azure-devops-task-fails-to-checkout-disabling-shallow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants