Repository navigation
[ISSUE]: GitVersion 6.0.5 fails to calculate the version and says the repo is shallow #4348
Copy link
Copy link
Closed
Description
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).
Reactions are currently unavailable
Activity
USBAkimbo commentedon Dec 12, 2024
For some more context, I'm having the exact same issue as #4094 as well
Output from Azure pipelines
https://github.com/GitTools/actions/blob/main/docs/cloning.md says to use the below
But as you can see, I've set the same thing and it fails
HHobeck commentedon 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:
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 commentedon Dec 13, 2024
Well that's the weird part - when I run with
6.0.5I getThe repository is shallowbut when I switch it to5.12.0I don't get that errorI 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
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
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)So it's definitely unshallow, but on that same run I got this
bermo commentedon 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 commentedon Dec 15, 2024
I'm not sure if it is constructive to repeat the sentence that it was working in version
5.12.0but having no steps to reproduce. I think you need to narrow down this problem by using additional logs or even debugging your scenario: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:
GitVersion/src/GitVersion.Core/Core/GitPreparer.cs
Line 190 in c63c1a3
For this the
LibGit2Sharplibrary in version0.30.0is 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.
SoucianceEqdamRashti commentedon Jan 3, 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: allUSBAkimbo commentedon Jan 6, 2025
Hey @SoucianceEqdamRashti that did the trick!
This now works
Using this GitVersion config (needed tweaking for v6)
arturcic commentedon Jan 9, 2025
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 commentedon Jan 14, 2025
Is this considered a fix 😱?
304NotModified commentedon Jul 10, 2025
This is still an issue. Why is this closed?
USBAkimbo commentedon Jul 10, 2025
I kept having issues with this so I downgraded to 5.12.0
I'm using the installed tool on my pipeline agents
I'm also running it using the /buildserver option to have it output the semver info to Azure DevOps