11using System ;
22using System . IO ;
33using System . Linq ;
4- using System . Text . RegularExpressions ;
54using GitVersion . Common ;
65using GitVersion . Configuration ;
76using GitVersion . Exceptions ;
@@ -47,20 +46,6 @@ public SemanticVersion FindVersion(GitVersionContext context)
4746 return FindVersionInternal ( context ) ;
4847 }
4948
50- private static void EnsureHeadIsNotDetached ( GitVersionContext context )
51- {
52- if ( ! context . CurrentBranch . IsDetachedHead ( ) )
53- {
54- return ;
55- }
56-
57- var message = string . Format (
58- "It looks like the branch being examined is a detached Head pointing to commit '{0}'. " +
59- "Without a proper branch name GitVersion cannot determine the build version." ,
60- context . CurrentCommit . Id . ToString ( 7 ) ) ;
61- throw new WarningException ( message ) ;
62- }
63-
6449 public SemanticVersion FindVersionInternal ( GitVersionContext context )
6550 {
6651 SemanticVersion taggedSemanticVersion = null ;
@@ -129,7 +114,7 @@ private SemanticVersion PerformIncrement(GitVersionContext context, BaseVersion
129114
130115 private void UpdatePreReleaseTag ( GitVersionContext context , SemanticVersion semanticVersion , string branchNameOverride )
131116 {
132- var tagToUse = GetBranchSpecificTag ( context . Configuration , context . CurrentBranch . FriendlyName , branchNameOverride ) ;
117+ var tagToUse = context . Configuration . GetBranchSpecificTag ( log , context . CurrentBranch . FriendlyName , branchNameOverride ) ;
133118
134119 int ? number = null ;
135120
@@ -152,27 +137,18 @@ private void UpdatePreReleaseTag(GitVersionContext context, SemanticVersion sema
152137 semanticVersion . PreReleaseTag = new SemanticVersionPreReleaseTag ( tagToUse , number ) ;
153138 }
154139
155- public string GetBranchSpecificTag ( EffectiveConfiguration configuration , string branchFriendlyName , string branchNameOverride )
140+ private static void EnsureHeadIsNotDetached ( GitVersionContext context )
156141 {
157- var tagToUse = configuration . Tag ;
158- if ( tagToUse == "useBranchName" )
142+ if ( ! context . CurrentBranch . IsDetachedHead ( ) )
159143 {
160- tagToUse = "{BranchName}" ;
144+ return ;
161145 }
162- if ( tagToUse . Contains ( "{BranchName}" ) )
163- {
164- log . Info ( "Using branch name to calculate version tag" ) ;
165-
166- var branchName = branchNameOverride ?? branchFriendlyName ;
167- if ( ! string . IsNullOrWhiteSpace ( configuration . BranchPrefixToTrim ) )
168- {
169- branchName = branchName . RegexReplace ( configuration . BranchPrefixToTrim , string . Empty , RegexOptions . IgnoreCase ) ;
170- }
171- branchName = branchName . RegexReplace ( "[^a-zA-Z0-9-]" , "-" ) ;
172146
173- tagToUse = tagToUse . Replace ( "{BranchName}" , branchName ) ;
174- }
175- return tagToUse ;
147+ var message = string . Format (
148+ "It looks like the branch being examined is a detached Head pointing to commit '{0}'. " +
149+ "Without a proper branch name GitVersion cannot determine the build version." ,
150+ context . CurrentCommit . Id . ToString ( 7 ) ) ;
151+ throw new WarningException ( message ) ;
176152 }
177153
178154 private static bool MajorMinorPatchEqual ( SemanticVersion lastTag , SemanticVersion baseVersion )
0 commit comments