@@ -90,19 +90,17 @@ public void execute() throws MojoExecutionException, MojoFailureException {
9090 try {
9191 while (StringUtils .isBlank (featureBranchName )) {
9292 featureBranchName = prompter
93- .prompt ("What is a name of feature branch? "
94- + gitFlowConfig
95- .getFeatureBranchPrefix ());
93+ .prompt ("What is a name of feature branch? " + gitFlowConfig .getFeatureBranchPrefix ());
9694
97- if (!validateBranchName (featureBranchName ,
98- featureNamePattern )) {
95+ if (!validateBranchName (featureBranchName , featureNamePattern , false )) {
9996 featureBranchName = null ;
10097 }
10198 }
10299 } catch (PrompterException e ) {
103100 throw new MojoFailureException ("feature-start" , e );
104101 }
105- } else if (validateBranchName (featureName , featureNamePattern )) {
102+ } else {
103+ validateBranchName (featureName , featureNamePattern , true );
106104 featureBranchName = featureName ;
107105 }
108106
@@ -164,18 +162,27 @@ public void execute() throws MojoExecutionException, MojoFailureException {
164162 }
165163 }
166164
167- private boolean validateBranchName (String name , String pattern )
165+ private boolean validateBranchName (String name , String pattern , boolean failOnError )
168166 throws MojoFailureException , CommandLineException {
169167 boolean valid = true ;
170168 if (StringUtils .isNotBlank (name ) && validBranchName (name )) {
171169 if (StringUtils .isNotBlank (pattern ) && !name .matches (pattern )) {
172- getLog (). warn ( "The name of the branch doesn't match '" + pattern
173- + "'." );
170+ final String error = "The name of the branch doesn't match '" + pattern + "' pattern." ;
171+ getLog (). warn ( error );
174172 valid = false ;
173+
174+ if (failOnError ) {
175+ throw new MojoFailureException (error );
176+ }
175177 }
176178 } else {
177- getLog ().warn ("The name of the branch is not valid." );
179+ final String error = "The name of the branch is not valid." ;
180+ getLog ().warn (error );
178181 valid = false ;
182+
183+ if (failOnError ) {
184+ throw new MojoFailureException (error );
185+ }
179186 }
180187 return valid ;
181188 }
0 commit comments