@@ -104,6 +104,12 @@ public enum ReleaseManagerOutputMode
104104 Json = 1 ,
105105 }
106106
107+ public void WriteToOutput ( ReleaseInfo releaseInfo )
108+ {
109+ string json = JsonConvert . SerializeObject ( releaseInfo , Formatting . Indented , new SemanticVersionJsonConverter ( ) ) ;
110+ this . stdout . WriteLine ( json ) ;
111+ }
112+
107113 /// <summary>
108114 /// Prepares a release for the specified directory by creating a release branch and incrementing the version in the current branch.
109115 /// </summary>
@@ -142,6 +148,24 @@ public ReleaseInfo PrepareRelease(string projectDirectory, string releaseUnstabl
142148 return this . PrepareReleaseCore ( projectDirectory , releaseUnstableTag , nextVersion , versionIncrement , outputMode , unformattedCommitMessage , whatIf ) ;
143149 }
144150
151+ private static bool IsVersionDecrement ( SemanticVersion oldVersion , SemanticVersion newVersion )
152+ {
153+ if ( newVersion . Version > oldVersion . Version )
154+ {
155+ return false ;
156+ }
157+ else if ( newVersion . Version == oldVersion . Version )
158+ {
159+ return string . IsNullOrEmpty ( oldVersion . Prerelease ) &&
160+ ! string . IsNullOrEmpty ( newVersion . Prerelease ) ;
161+ }
162+ else
163+ {
164+ // newVersion.Version < oldVersion.Version
165+ return true ;
166+ }
167+ }
168+
145169 /// <summary>
146170 /// Core implementation of prepare-release functionality that can either simulate or execute the operation.
147171 /// </summary>
@@ -252,18 +276,10 @@ private ReleaseInfo PrepareReleaseCore(string projectDirectory, string releaseUn
252276 throw new ReleasePreparationException ( ReleasePreparationError . BranchAlreadyExists ) ;
253277 }
254278
255- if ( outputMode == ReleaseManagerOutputMode . Text )
279+ if ( outputMode == ReleaseManagerOutputMode . Text && whatIf )
256280 {
257- if ( whatIf )
258- {
259- this . stdout . WriteLine ( $ "What-if: { releaseBranchName } branch would track v{ releaseVersion } stabilization and release.") ;
260- this . stdout . WriteLine ( $ "What-if: { originalBranchName } branch would track v{ nextDevVersion } development.") ;
261- }
262- else
263- {
264- this . stdout . WriteLine ( $ "{ releaseBranchName } branch now tracks v{ releaseVersion } stabilization and release.") ;
265- this . stdout . WriteLine ( $ "{ originalBranchName } branch now tracks v{ nextDevVersion } development.") ;
266- }
281+ this . stdout . WriteLine ( $ "What-if: { releaseBranchName } branch would track v{ releaseVersion } stabilization and release.") ;
282+ this . stdout . WriteLine ( $ "What-if: { originalBranchName } branch would track v{ nextDevVersion } development.") ;
267283 }
268284
269285 var originalBranchInfo = new ReleaseBranchInfo ( originalBranchName , repository . Head . Tip . Sha , nextDevVersion ) ;
@@ -280,10 +296,20 @@ private ReleaseInfo PrepareReleaseCore(string projectDirectory, string releaseUn
280296 global ::LibGit2Sharp . Commands . Checkout ( repository , releaseBranch ) ;
281297 this . UpdateVersion ( context , versionOptions . Version , releaseVersion , unformattedCommitMessage ) ;
282298
299+ if ( outputMode == ReleaseManagerOutputMode . Text )
300+ {
301+ this . stdout . WriteLine ( $ "{ releaseBranchName } branch now tracks v{ releaseVersion } stabilization and release.") ;
302+ }
303+
283304 // update version on main branch
284305 global ::LibGit2Sharp . Commands . Checkout ( repository , originalBranchName ) ;
285306 this . UpdateVersion ( context , versionOptions . Version , nextDevVersion , unformattedCommitMessage ) ;
286307
308+ if ( outputMode == ReleaseManagerOutputMode . Text )
309+ {
310+ this . stdout . WriteLine ( $ "{ originalBranchName } branch now tracks v{ nextDevVersion } development.") ;
311+ }
312+
287313 // Merge release branch back to main branch
288314 var mergeOptions = new MergeOptions ( )
289315 {
@@ -298,37 +324,13 @@ private ReleaseInfo PrepareReleaseCore(string projectDirectory, string releaseUn
298324 var finalOriginalBranchInfo = new ReleaseBranchInfo ( originalBranchName , repository . Head . Tip . Sha , nextDevVersion ) ;
299325 var finalReleaseBranchInfo = new ReleaseBranchInfo ( releaseBranchName , repository . Branches [ releaseBranchName ] . Tip . Id . ToString ( ) , releaseVersion ) ;
300326 var finalReleaseInfo = new ReleaseInfo ( finalOriginalBranchInfo , finalReleaseBranchInfo ) ;
301-
327+
302328 this . WriteToOutput ( finalReleaseInfo ) ;
303329 }
304330
305331 return null ;
306332 }
307333
308- public void WriteToOutput ( ReleaseInfo releaseInfo )
309- {
310- string json = JsonConvert . SerializeObject ( releaseInfo , Formatting . Indented , new SemanticVersionJsonConverter ( ) ) ;
311- this . stdout . WriteLine ( json ) ;
312- }
313-
314- private static bool IsVersionDecrement ( SemanticVersion oldVersion , SemanticVersion newVersion )
315- {
316- if ( newVersion . Version > oldVersion . Version )
317- {
318- return false ;
319- }
320- else if ( newVersion . Version == oldVersion . Version )
321- {
322- return string . IsNullOrEmpty ( oldVersion . Prerelease ) &&
323- ! string . IsNullOrEmpty ( newVersion . Prerelease ) ;
324- }
325- else
326- {
327- // newVersion.Version < oldVersion.Version
328- return true ;
329- }
330- }
331-
332334 private string GetReleaseBranchName ( VersionOptions versionOptions )
333335 {
334336 Requires . NotNull ( versionOptions , nameof ( versionOptions ) ) ;
0 commit comments