@@ -48,6 +48,7 @@ public virtual NextVersion FindVersion()
48
48
}
49
49
50
50
var nextVersion = Calculate ( Context . CurrentBranch , Context . Configuration ) ;
51
+ var preReleaseTagName = nextVersion . Configuration . GetBranchSpecificTag ( this . log , Context . CurrentBranch . Name . Friendly , nextVersion . BaseVersion . BranchNameOverride ) ;
51
52
52
53
SemanticVersion semver ;
53
54
if ( Context . Configuration . VersioningMode == VersioningMode . Mainline )
@@ -67,61 +68,44 @@ public virtual NextVersion FindVersion()
67
68
{
68
69
semver = nextVersion . BaseVersion . SemanticVersion ;
69
70
}
70
- }
71
-
72
- var tag = nextVersion . Configuration . Tag ;
73
- if ( ! tag . IsNullOrEmpty ( ) && semver . PreReleaseTag ? . Name != tag )
74
- {
75
- UpdatePreReleaseTag ( new ( nextVersion . Branch , nextVersion . Configuration ) , semver , nextVersion . BaseVersion . BranchNameOverride ) ;
76
- }
77
-
78
- // TODO: It is totally unimportant that the current commit has been tagged or not IMO. We can make a double check actually if the result
79
- // is the same or make it configurable but each run should be deterministic.Even if the development process goes on the tagged commit
80
- // should always calculating the same result. Otherwise something is wrong with the configuration or someone messed up the branching history.
81
-
82
- if ( Context . IsCurrentCommitTagged )
83
- {
84
- // Will always be 0, don't bother with the +0 on tags
85
- var semanticVersionBuildMetaData = this . mainlineVersionCalculator . CreateVersionBuildMetaData ( Context . CurrentCommit ! ) ;
86
- semanticVersionBuildMetaData . CommitsSinceTag = null ;
87
71
88
- SemanticVersion taggedSemanticVersion = new SemanticVersion ( Context . CurrentCommitTaggedVersion ) { BuildMetaData = semanticVersionBuildMetaData } ;
72
+ var lastPrefixedSemver = this . repositoryStore
73
+ . GetVersionTagsOnBranch ( Context . CurrentBranch , Context . Configuration . TagPrefix )
74
+ . Where ( v => MajorMinorPatchEqual ( v , semver ) && v . PreReleaseTag ? . HasTag ( ) == true )
75
+ . FirstOrDefault ( v => v . PreReleaseTag ? . Name ? . IsEquivalentTo ( preReleaseTagName ) == true ) ;
89
76
90
- // replace calculated version with tagged version only if tagged version greater or equal to calculated version
91
- if ( taggedSemanticVersion . CompareTo ( semver , false ) >= 0 )
77
+ if ( lastPrefixedSemver != null )
92
78
{
93
- // set the commit count on the tagged ver
94
- taggedSemanticVersion . BuildMetaData . CommitsSinceVersionSource = semver . BuildMetaData ? . CommitsSinceVersionSource ;
95
-
96
- semver = taggedSemanticVersion ;
79
+ semver . PreReleaseTag = lastPrefixedSemver . PreReleaseTag ;
97
80
}
98
81
}
99
82
100
- return new ( semver , nextVersion . BaseVersion , new ( nextVersion . Branch , nextVersion . Configuration ) ) ;
101
- }
102
-
103
- private void UpdatePreReleaseTag ( EffectiveBranchConfiguration configuration , SemanticVersion semanticVersion , string ? branchNameOverride )
104
- {
105
- var preReleaseTagName = configuration . Value . GetBranchSpecificTag ( this . log , Context . CurrentBranch . Name . Friendly , branchNameOverride ) ;
106
-
107
- // TODO: Please update the pre release-tag in the IVersionStrategy implementation.
108
- var lastPrefixedSemver = this . repositoryStore
109
- . GetVersionTagsOnBranch ( Context . CurrentBranch , Context . Configuration . TagPrefix )
110
- . Where ( v => MajorMinorPatchEqual ( v , semanticVersion ) && v . HasPreReleaseTagWithLabel )
111
- . FirstOrDefault ( v => v . PreReleaseTag ? . Name ? . IsEquivalentTo ( preReleaseTagName ) == true ) ;
112
-
113
- long ? number = null ;
114
-
115
- if ( lastPrefixedSemver != null )
83
+ if ( semver . CompareTo ( Context . CurrentCommitTaggedVersion ) == 0 )
116
84
{
117
- number = lastPrefixedSemver . PreReleaseTag ! . Number + 1 ;
85
+ // Will always be 0, don't bother with the +0 on tags
86
+ semver . BuildMetaData . CommitsSinceTag = null ;
87
+ }
88
+ else if ( string . IsNullOrEmpty ( preReleaseTagName ) )
89
+ {
90
+ semver . PreReleaseTag = new SemanticVersionPreReleaseTag ( ) ;
118
91
}
119
92
else
120
93
{
121
- number = 1 ;
94
+ long ? number ;
95
+
96
+ if ( semver . PreReleaseTag . Name == preReleaseTagName )
97
+ {
98
+ number = semver . PreReleaseTag . Number + 1 ;
99
+ }
100
+ else
101
+ {
102
+ number = 1 ;
103
+ }
104
+
105
+ semver . PreReleaseTag = new SemanticVersionPreReleaseTag ( preReleaseTagName , number ) ;
122
106
}
123
107
124
- semanticVersion . PreReleaseTag = new SemanticVersionPreReleaseTag ( preReleaseTagName , number ) ;
108
+ return new ( semver , nextVersion . BaseVersion , new ( nextVersion . Branch , nextVersion . Configuration ) ) ;
125
109
}
126
110
127
111
private static void EnsureHeadIsNotDetached ( GitVersionContext context )
0 commit comments