GitVersion
GitVersion copied to clipboard
[Bug] Characters truncated in branches with underscore
Describe the bug
For a branch named like release/PWB-1234_Description-1, the FullSemVer version generated by GitVersion is broken (1.0.0-PWB1782-Phase.50).
The format that seems to apply:
- Underscore is replaced by hyphen (which is ok)
- We loose two times the "-1" (which is wrong)
Generated variables:
{
"Major": 1,
"Minor": 0,
"Patch": 0,
"AssemblySemVer": "1.0.0.0",
"AssemblySemFileVer": "1.0.0.50",
"FullSemVer": "1.0.0-PWB1782-Phase.50",
"InformationalVersion": "1.0.0-PWB1782-Phase.50+Branch.release-PWB-11782-Phase-1.Sha.7c6a88f5544c263a65f30a4ac57d5cc33550caeb",
"BranchName": "release/PWB-11782_Phase-1",
"EscapedBranchName": "release-PWB-11782-Phase-1",
"Sha": "7c6a88f5544c263a65f30a4ac57d5cc33550caeb",
"ShortSha": "7c6a88f",
"NuGetVersionV2": "1.0.0-pwb1782-phase0050",
"NuGetVersion": "1.0.0-pwb1782-phase0050",
"NuGetPreReleaseTagV2": "pwb1782-phase0050",
"NuGetPreReleaseTag": "pwb1782-phase0050",
"VersionSourceSha": "8aa4851270ac77cadc14fea8d8d44db75b526bf6",
"CommitsSinceVersionSource": 50,
"CommitsSinceVersionSourcePadded": "0050",
"UncommittedChanges": 18239,
"CommitDate": "2022-03-11"
}
GitVersion.yml:
mode: ContinuousDeployment
assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatchTag
assembly-informational-format: '{InformationalVersion}'
next-version: 1.0.0 #Version à incrémenter manuellement
commit-message-incrementing: Disabled
branches:
main:
regex: ^master$|^main$ #S'applique aux branche "main" et "master"
mode: ContinuousDelivery #Ne génère pas de version unique à chaque commit
tag: '' #Aucun tag de prerelease ajouté
increment: none #Pas d'incrément automatique
is-release-branch: false
is-mainline: true
prevent-increment-of-merged-branch-version: true
track-merge-target: false
tracks-release-branches: false
feature:
regex: ^(feature|bugfix)[\/] #S'applique aux branche "feature" et "bugfix"
mode: ContinuousDeployment #Génère une version unique à chaque commit
tag: useBranchName #Utilise le nom de la branche comme tag de prerelease
increment: none #Pas d'incrément automatique
source-branches: ['master', 'release'] #Possibles parents de la branche
track-merge-target: false
tracks-release-branches: false
is-release-branch: false
release:
regex: ^release?[\/] #S'applique aux branche "release"
mode: ContinuousDeployment #Ne génère pas de version unique à chaque commit
tag: useBranchName
increment: none
source-branches: ['master']
prevent-increment-of-merged-branch-version: true
track-merge-target: false
tracks-release-branches: false
is-release-branch: true
hotfix:
regex: ^hotfix[\/] #S'applique aux branche "hotfix"
mode: ContinuousDeployment #Génère une version unique à chaque commit
tag: useBranchName
increment: none
source-branches: ['master']
prevent-increment-of-merged-branch-version: true
track-merge-target: false
tracks-release-branches: false
is-release-branch: false
Expected Behavior
GitVersion generate a FullSemVer version that contains all the branch name characters as the pre-release tag.
Actual Behavior
GitVersion generate a FullSemVer version that truncates some characters unexpectedly.
Possible Fix
Fix the formatting step when generating the version.
Steps to Reproduce
- Create a branch named
release/PWB-1234_Description-1 - Execute GitVersion
- Consult the generated version
Context
I want to be able to use the generated FullSemVer as the build identifier and for a Nuget package too. It is working well most of the time, but some characters in branch names provoke odd behaviours in GitVersion.
Your Environment
We detected this problem in an AzureDevOps CI pipeline, but the same behavior is present when commands runs locally.
- Version Used: GitVersion.Tool 5.9.0 x64
- Operating System and version: Ubuntu 20.04.4
Thanks!
I tried to use {EscapedBranchName} as the pre-release tag in my GitVersion.yml
mode: ContinuousDeployment
assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatchTag
assembly-informational-format: '{InformationalVersion}'
next-version: 1.0.0 #Version à incrémenter manuellement
commit-message-incrementing: Disabled
branches:
main:
regex: ^master$|^main$ #S'applique aux branche "main" et "master"
mode: ContinuousDelivery #Ne génère pas de version unique à chaque commit
tag: '' #Aucun tag de prerelease ajouté
increment: none #Pas d'incrément automatique
is-release-branch: false
is-mainline: true
prevent-increment-of-merged-branch-version: true
track-merge-target: false
tracks-release-branches: false
feature:
regex: ^(feature|bugfix)[\/] #S'applique aux branche "feature" et "bugfix"
mode: ContinuousDeployment #Génère une version unique à chaque commit
tag: {EscapedBranchName} #Utilise le nom de la branche comme tag de prerelease
increment: none #Pas d'incrément automatique
source-branches: ['master', 'release'] #Possibles parents de la branche
track-merge-target: false
tracks-release-branches: false
is-release-branch: false
release:
regex: ^release?[\/] #S'applique aux branche "release"
mode: ContinuousDeployment #Ne génère pas de version unique à chaque commit
tag: {EscapedBranchName}
increment: none
source-branches: ['master']
prevent-increment-of-merged-branch-version: true
track-merge-target: false
tracks-release-branches: false
is-release-branch: true
hotfix:
regex: ^hotfix[\/] #S'applique aux branche "hotfix"
mode: ContinuousDeployment #Génère une version unique à chaque commit
tag: {EscapedBranchName}
increment: none
source-branches: ['master']
prevent-increment-of-merged-branch-version: true
track-merge-target: false
tracks-release-branches: false
is-release-branch: false
I was expecting to have the same behavior as using {BranchName}.
What happens if you remove next-version: 1.0.0?
It seems to fix the problem, but we use this configuration property to control our version manually. It is not a viable option for us to remove it.
{
"Major": 0,
"Minor": 1,
"Patch": 0,
"BranchName": "bugfix/git-111_version-1",
"EscapedBranchName": "bugfix-git-111-version-1",
"Sha": "71ef7c274c1c266ae066e9600433504882ce11e0",
"ShortSha": "71ef7c2",
"NuGetVersionV2": "0.1.0-git-111-version-0052",
"NuGetVersion": "0.1.0-git-111-version-0052",
"NuGetPreReleaseTagV2": "git-111-version-0052",
"NuGetPreReleaseTag": "git-111-version-0052",
"VersionSourceSha": "1d9ae3a3ff579c60c7de4831db415806989aaa04",
"CommitsSinceVersionSource": 52,
"CommitsSinceVersionSourcePadded": "0052",
"UncommittedChanges": 18239,
"CommitDate": "2022-03-15"
}
Why are you unable to use git tag?
We use git tag only on the main branch, but we want to generate versions during the development process on other branches. We increment the version only when on main, so during development we always use the latest release version from which we append the pre-release tag via the pipeline. I don't think using git tag on almost every build would be a good option for us.
Why would you need to use git tag on every build? Do you change the value of next-version on every build?
No, but if I remove next-version: from the Gitversion.yml, which version will be used? I have a version key in my .csproj but it seem to be ignored when gitversion is executed.
For exemple I have this .csproj:

And the generated version is:
{
"Major": 0,
"Minor": 1,
"Patch": 0,
"BranchName": "bugfix/git-111_version-1",
"EscapedBranchName": "bugfix-git-111-version-1",
"Sha": "71ef7c274c1c266ae066e9600433504882ce11e0",
"ShortSha": "71ef7c2",
"NuGetVersionV2": "0.1.0-git-111-version-0052",
"NuGetVersion": "0.1.0-git-111-version-0052",
"NuGetPreReleaseTagV2": "git-111-version-0052",
"NuGetPreReleaseTag": "git-111-version-0052",
"VersionSourceSha": "1d9ae3a3ff579c60c7de4831db415806989aaa04",
"CommitsSinceVersionSource": 52,
"CommitsSinceVersionSourcePadded": "0052",
"UncommittedChanges": 18239,
"CommitDate": "2022-03-15"
} ```
No, but if I remove
next-version:from the Gitversion.yml, which version will be used?
The highest git tag GitVersion can find from the current branch. If you add git tag 1.0.0 to a historical commit on main, it's going to affect the version calculation of all branches in the repository.
I have a version key in my .csproj but it seem to be ignored when gitversion is executed.
I think you've got this backwards. GitVersion only uses the Git history and GitVersion.yml to perform its version calculation. You can use GitVersion to patch version numbers into AssemblyInfo.cs, .csproj files and such, but not the other way around.
I understand, thank your for the explanation. Seems we will have to use git tag as a required step in our team developement workflow. I know it is a good practice but right now we do not use it systematically, reason why we used next-version.
Sounds good. Can this be closed, then?
If I execute the following integration test then I cannot see any problems. This issue might be solved.
[Test]
public void __Just_A_Test__()
{
var configuration = GitFlowConfigurationBuilder.New.WithNextVersion("1.2.0").Build();
using var fixture = new EmptyRepositoryFixture();
fixture.Repository.MakeATaggedCommit("1.0.0");
fixture.BranchTo("feature/PWB-1234_Description-1");
fixture.Repository.MakeACommit();
// ✅ succeeds as expected
fixture.AssertFullSemver("1.2.0-PWB-1234-Description-1.1+4", configuration);
}