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