Skip to content

[ISSUE]: GitVersion 6.0.5 fails to calculate the version and says the repo is shallow #4348

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

Closed
2 tasks done
USBAkimbo opened this issue Dec 12, 2024 · 9 comments
Closed
2 tasks done

Comments

@USBAkimbo
Copy link

USBAkimbo commented Dec 12, 2024

Prerequisites

  • I have written a descriptive issue title
  • I have searched issues to ensure it has not already been reported

GitVersion package

AzureDevops task, GitVersion.Tool

GitVersion version

6.0.5 and 5.12.0

Operating system

Linux

What are you seeing?

Here is my 5.12.0 config that works

# dotnet-tools.json
{
  "version": 1,
  "isRoot": true,
  "tools": {   
    "gitversion.tool": {
      "version": "5.12.0",
      "commands": [
        "dotnet-gitversion"
      ]
    }
  }
}
# gitversion.yml
assembly-informational-format: '{FullSemVer}'
branches:
  feature:
    mode: ContinuousDeployment
    regex: features?[/-]
    tag: feature.{BranchName}
  develop:
    regex: dev(elop)?(ment)?$
  master:
    regex: master$
  pull-request:
    regex: (pull|pull\-requests|pr)[/-]
    mode: ContinuousDelivery
    tag: pr
    increment: Inherit
    tag-number-pattern: '[/-](?<number>\d+)[-/]'
    track-merge-target: false
    tracks-release-branches: false
    is-release-branch: false
# azure-pipelines.yml
          - checkout: self
            clean: true
            fetchDepth: '0' # Clone full repo history for GitVersion to work

          - task: Bash@3
            displayName: Determine GitVersion
            inputs:
              targetType: inline
              script: |
                echo "=== Install GitVersion version as defined in .config/dotnet-tools.json ==="
                dotnet tool restore

                echo "=== Run GitVersion and select the semantic version ==="
                SEMVER=$(dotnet gitversion | grep '"SemVer"' | cut -d'"' -f 4)
                echo "Semantic version is: $SEMVER"

                echo "=== Exit with an error if the output is null ==="
                if [ -z "$SEMVER" ]; then
                  echo "Error: Failed to extract semver"
                  exit 1
                fi

                echo "=== Export SEMVER variable for use with other stages ==="
                echo "##vso[task.setvariable variable=SEMVER;isOutput=true]$SEMVER"

I'm using the actual GitVersion commands rather than the ADO task because we keep getting random errors with 5.12.0 - sometimes it works and sometimes it fails with error: undefined message

Now when I change the below config options for version 6.0.5, it doesn't work

# dotnet-tools.json
{
  "version": 1,
  "isRoot": true,
  "tools": {   
    "gitversion.tool": {
      "version": "6.0.5",
      "commands": [
        "dotnet-gitversion"
      ]
    }
  }
}
# gitversion.yml
assembly-informational-format: '{FullSemVer}'
branches:
  feature:
    mode: ContinuousDeployment
    regex: features?[/-]
    label: feature.{BranchName}
  develop:
    regex: dev(elop)?(ment)?$
  master:
    regex: master$
  pull-request:
    regex: (pull|pull\-requests|pr)[/-]
    mode: ContinuousDelivery
    label: pr
    increment: Inherit
    label-number-pattern: '[/-](?<number>\d+)[-/]'
    track-merge-target: false
    tracks-release-branches: false
    is-release-branch: false

I just get this error

INFO [24-12-12 16:47:02:99] HEAD points at branch 'refs/heads/feature/dev-env-mig'.
INFO [24-12-12 16:47:02:99] -< End: Normalizing git directory for branch 'refs/heads/feature/dev-env-mig' (Took: 259.26ms) >-
WARN [24-12-12 16:47:02:99] An error occurred:
Repository is a shallow clone. Git repositories must contain the full history. See https://gitversion.net/docs/reference/requirements#unshallow for more info.
Semantic version is: 
=== Exit with an error if the output is null ===

And as you can see above, it's lying to me - this is definitely a shallow clone

What is expected?

I know with v6 I have to make some config changes to gitversion.yml which I've done - yet the error doesn't make sense because IT IS a full clone of the repo

Steps to Reproduce

Use the above config to make a pipeline with the defined config and run it

It should work with 5.12.0 and fail with 6.0.5

RepositoryFixture Test

No response

Output log or link to your CI build (if appropriate).

@USBAkimbo
Copy link
Author

For some more context, I'm having the exact same issue as #4094 as well

# azure-pipelines.yml
          - checkout: self
            fetchDepth: '0' # Clone full repo history for GitVersion to work

          - task: gitversion/setup@3
            displayName: Install GitVersion
            inputs:
              versionSpec: "5.12.0"

          - task: gitversion/execute@3
            displayName: Determine Version
            name: Version
            inputs:
              useConfigFile: true
              configFilePath: GitVersion.yml

Output from Azure pipelines

Starting: Determine Version
==============================================================================
Task         : Execute GitVersion Task
Description  : Easy Semantic Versioning (https://semver.org) for projects using Git
Version      : 3.1.1
Author       : GitTools Contributors
Help         : See the [documentation](https://gitversion.net/docs/) for help
==============================================================================
Running on: 'Azure Pipelines'
Disable Telemetry
Command: git -C /azp/_work/1/s rev-parse --is-shallow-repository
##[error]The repository is shallow. Consider disabling shallow clones. See https://github.com/GitTools/actions/blob/main/docs/cloning.md for more information.
##[error]The repository is shallow. Consider disabling shallow clones. See https://github.com/GitTools/actions/blob/main/docs/cloning.md for more information.
Finishing: Determine Version

https://github.com/GitTools/actions/blob/main/docs/cloning.md says to use the below

steps:
  - checkout: self
    displayName: Checkout
    fetchDepth: '0'

But as you can see, I've set the same thing and it fails

@HHobeck
Copy link
Contributor

HHobeck commented Dec 13, 2024

If I see the following log output I would say that a native git command is used to determine whether or not a shallow checkout happens:

Command: git -C /azp/_work/1/s rev-parse --is-shallow-repository
##[error]The repository is shallow. Consider disabling shallow clones. See https://github.com/GitTools/actions/blob/main/docs/cloning.md for more information.

Have you tried this git command by yourself? What is the outcome? Why do you think it is a problem in GitVersion and not in git? Have you thought about that your repository is corrupt? Can you provide steps to reproduce?

Question about question.

@USBAkimbo
Copy link
Author

Well that's the weird part - when I run with 6.0.5 I get The repository is shallow but when I switch it to 5.12.0 I don't get that error

I just tested it with the git command above and it shows the same as above - shallow for v6 but not for v5

I did think it could be a corrupt repo, but this is my preceding step

# azure-pipelines.yml
- checkout: self
  clean: true
  fetchDepth: '0' # Clone full repo history for GitVersion to work

It's scorching the repo before it pulls it and starts from a clean slate each time

I believe that using the above config in my original post should allow you to reproduce the issue within an ADO environment

As a workaround, I've updated my ADO tasks to this

          - checkout: self
            displayName: Clone Git repo
            clean: true
            fetchDepth: '0' # Clone full repo history for GitVersion to work

          - task: gitversion/setup@0
            displayName: Install GitVersion
            retryCountOnTaskFailure: 10
            inputs:
              versionSpec: "5.12.0"

          - task: gitversion/execute@0
            displayName: Determine Version
            retryCountOnTaskFailure: 10
            name: Version
            inputs:
              useConfigFile: true
              configFilePath: GitVersion.yml

I've added in 10 retries on the setup and calculate steps - we see bizarre behaviour where sometimes the pipeline will fail to determine the version with an error, but if we run it again, it works

That would imply an issue with the pipeline agent, but we're using Docker to spawn pristine containers each time with their own clean working environment (not that it really matters because it fresh clones the repo each time anyway)

And on the Git checkout step, I see this (with 5.12.0)

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

So it's definitely unshallow, but on that same run I got this

Starting: Determine Version
==============================================================================
Task         : Execute GitVersion Task
Description  : Easy Semantic Versioning (https://semver.org) for projects using Git
Version      : 2.0.1
Author       : GitTools Contributors
Help         : See the [documentation](https://gitversion.net/docs/) for help
==============================================================================
Running on: 'Azure Pipelines'
Disable Telemetry
Executing GitVersion
Command: git -C /azp/_work/1/s rev-parse --is-shallow-repository
##[error]The repository is shallow. Consider disabling shallow clones. See https://github.com/GitTools/actions/blob/main/docs/cloning.md for more information.
Finishing: Determine Version

@bermo
Copy link

bermo commented Dec 14, 2024

We have been experiencing similar issues since upgrading to version 6.x. It seems to fail approx 1-2% of the time on our build agents. Sometimes the only way we can get the build completed is to kill the specific agent that it has been previously failing on. We didn't experience any shallow clone issues like this using version 5.x either.

@HHobeck
Copy link
Contributor

HHobeck commented Dec 15, 2024

I'm not sure if it is constructive to repeat the sentence that it was working in version 5.12.0 but having no steps to reproduce. I think you need to narrow down this problem by using additional logs or even debugging your scenario:

  • make a diff of the source code after it was broken
  • create a build step and execute: git rev-parse --is-shallow-repository
  • save the repository and debug it locally

I mean you have not answered the question what the result is of using native git command. What are you expecting from the community?

The following line is used to detect shallow clones:

if (this.repository.IsShallow)

For this the LibGit2Sharp library in version 0.30.0 is used. Maybe you need to open an issue there. Thus I'm going to close this issue. Please create a new issue if you have more information and know that the bug is located in gitversion.

Thank you very much.

@HHobeck HHobeck closed this as completed Dec 15, 2024
@SoucianceEqdamRashti
Copy link

I also had this issue. At least for Azure DevOps set this before all the steps in your job and that should help to resolve it.
workspace: clean: all

@USBAkimbo
Copy link
Author

Hey @SoucianceEqdamRashti that did the trick!

This now works

# azure-pipelines.yml
stages:
  - stage: CalculateVariables
    displayName: Calculate Variables
    jobs:
      - job: semver
        displayName: Establish Semantic Version
        workspace:
          clean: all
        pool: Default
        steps:
          - script: |
              echo "Cleaning up any pre-existing lock files"
              find . -name '*merge.lock' -print -delete
            displayName: Force cleanup lock files

          - checkout: self
            displayName: Clone Git repo
            clean: true
            fetchDepth: '0' # Clone full repo history for GitVersion to work

          - task: gitversion/setup@0
            displayName: Install GitVersion
            retryCountOnTaskFailure: 10
            inputs:
              versionSpec: "6.0.5"

          - task: gitversion/execute@0
            displayName: Determine Version
            name: Version
            inputs:
              useConfigFile: true
              configFilePath: GitVersion.yml

Using this GitVersion config (needed tweaking for v6)

# GitVersion.yml
assembly-informational-format: '{FullSemVer}'
branches:
  feature:
    mode: ContinuousDeployment
    regex: features?[/-]
    label: feature.{BranchName}
  develop:
    regex: dev(elop)?(ment)?$
  master:
    regex: master$
  pull-request:
    regex: (pull|pull\-requests|pr)[/-]
    mode: ContinuousDelivery
    label: pr
    increment: Inherit
    label-number-pattern: '[/-](?<number>\d+)[-/]'
    track-merge-target: false
    tracks-release-branches: false
    is-release-branch: false

@arturcic
Copy link
Member

arturcic commented Jan 9, 2025

I also had this issue. At least for Azure DevOps set this before all the steps in your job and that should help to resolve it. workspace: clean: all

Hey @SoucianceEqdamRashti can you create a PR in the https://github.com/GitTools/actions/blob/main/docs/examples/azure/gitversion/setup.md#usage-examples as well?

@HofmeisterAn
Copy link

I also had this issue. At least for Azure DevOps set this before all the steps in your job and that should help to resolve it. workspace: clean: all

Hey @SoucianceEqdamRashti can you create a PR in the https://github.com/GitTools/actions/blob/main/docs/examples/azure/gitversion/setup.md#usage-examples as well?

Is this considered a fix 😱?

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

6 participants