11using GitVersion . Configuration ;
22using GitVersion . Core . Tests . Helpers ;
3+ using GitVersion . Helpers ;
4+ using LibGit2Sharp ;
35
46namespace GitVersion . Core . Tests . IntegrationTests ;
57
@@ -9,24 +11,29 @@ public class GitflowScenarios : TestBase
911 [ Test ]
1012 public void GitflowComplexExample ( )
1113 {
14+ var keepBranches = true ;
1215 const string developBranch = "develop" ;
1316 const string feature1Branch = "feature/f1" ;
1417 const string feature2Branch = "feature/f2" ;
1518 const string release1Branch = "release/1.1.0" ;
1619 const string release2Branch = "release/1.2.0" ;
1720 const string hotfixBranch = "hotfix/hf" ;
21+
1822 var configuration = GitFlowConfigurationBuilder . New . Build ( ) ;
1923
20- using var fixture = new BaseGitFlowRepositoryFixture ( "1.0.0" ) ;
21- fixture . AssertFullSemver ( "1.1.0-alpha.1" , configuration ) ;
24+ using var fixture = new BaseGitFlowRepositoryFixture ( initialMainAction , deleteOnDispose : false ) ;
25+ var fullSemver = "1.1.0-alpha.1" ;
26+ fixture . AssertFullSemver ( fullSemver , configuration ) ;
2227
2328 // Feature 1
2429 fixture . BranchTo ( feature1Branch ) ;
25- fixture . MakeACommit ( "added feature 1" ) ;
26- fixture . AssertFullSemver ( "1.1.0-f1.1+2" , configuration ) ;
30+
31+ fixture . MakeACommit ( $ "added feature 1 >> { fullSemver } ") ;
32+ fullSemver = "1.1.0-f1.1+2" ;
33+ fixture . AssertFullSemver ( fullSemver , configuration ) ;
2734 fixture . Checkout ( developBranch ) ;
2835 fixture . MergeNoFF ( feature1Branch ) ;
29- fixture . Repository . Branches . Remove ( fixture . Repository . Branches [ feature1Branch ] ) ;
36+ if ( ! keepBranches ) fixture . Repository . Branches . Remove ( fixture . Repository . Branches [ feature1Branch ] ) ;
3037 fixture . AssertFullSemver ( "1.1.0-alpha.3" , configuration ) ;
3138
3239 // Release 1.1.0
@@ -45,40 +52,99 @@ public void GitflowComplexExample()
4552
4653 // Feature 2
4754 fixture . BranchTo ( feature2Branch ) ;
48- fixture . MakeACommit ( "added feature 2" ) ;
49- fixture . AssertFullSemver ( "1.2.0-f2.1+2" , configuration ) ;
55+ fullSemver = "1.2.0-f2.1+2" ;
56+ fixture . MakeACommit ( $ "added feature 2 >> { fullSemver } ") ;
57+ fixture . AssertFullSemver ( fullSemver , configuration ) ;
5058 fixture . Checkout ( developBranch ) ;
5159 fixture . MergeNoFF ( feature2Branch ) ;
52- fixture . Repository . Branches . Remove ( fixture . Repository . Branches [ feature2Branch ] ) ;
60+ if ( ! keepBranches ) fixture . Repository . Branches . Remove ( fixture . Repository . Branches [ feature2Branch ] ) ;
5361 fixture . AssertFullSemver ( "1.2.0-alpha.3" , configuration ) ;
5462
5563 // Release 1.2.0
5664 fixture . BranchTo ( release2Branch ) ;
57- fixture . MakeACommit ( "release stabilization" ) ;
58- fixture . AssertFullSemver ( "1.2.0-beta.1+8" , configuration ) ;
65+ fullSemver = "1.2.0-beta.1+8" ;
66+ fixture . MakeACommit ( $ "release stabilization >> { fullSemver } ") ;
67+ fixture . AssertFullSemver ( fullSemver , configuration ) ;
5968 fixture . Checkout ( MainBranch ) ;
6069 fixture . MergeNoFF ( release2Branch ) ;
6170 fixture . AssertFullSemver ( "1.2.0-5" , configuration ) ;
6271 fixture . ApplyTag ( "1.2.0" ) ;
6372 fixture . AssertFullSemver ( "1.2.0" , configuration ) ;
6473 fixture . Checkout ( developBranch ) ;
6574 fixture . MergeNoFF ( release2Branch ) ;
66- fixture . Repository . Branches . Remove ( fixture . Repository . Branches [ release2Branch ] ) ;
75+ if ( ! keepBranches ) fixture . Repository . Branches . Remove ( fixture . Repository . Branches [ release2Branch ] ) ;
6776 fixture . AssertFullSemver ( "1.3.0-alpha.1" , configuration ) ;
6877
6978 // Hotfix
7079 fixture . Checkout ( MainBranch ) ;
7180 fixture . BranchTo ( hotfixBranch ) ;
72- fixture . MakeACommit ( "added hotfix" ) ;
73- fixture . AssertFullSemver ( "1.2.1-beta.1+1" , configuration ) ;
81+ fullSemver = "1.2.1-beta.1+1" ;
82+ fixture . MakeACommit ( $ "added hotfix >> { fullSemver } ") ;
83+ fixture . AssertFullSemver ( fullSemver , configuration ) ;
7484 fixture . Checkout ( MainBranch ) ;
7585 fixture . MergeNoFF ( hotfixBranch ) ;
7686 fixture . AssertFullSemver ( "1.2.1-2" , configuration ) ;
7787 fixture . ApplyTag ( "1.2.1" ) ;
7888 fixture . AssertFullSemver ( "1.2.1" , configuration ) ;
7989 fixture . Checkout ( developBranch ) ;
8090 fixture . MergeNoFF ( hotfixBranch ) ;
81- fixture . Repository . Branches . Remove ( fixture . Repository . Branches [ hotfixBranch ] ) ;
91+ if ( ! keepBranches ) fixture . Repository . Branches . Remove ( fixture . Repository . Branches [ hotfixBranch ] ) ;
8292 fixture . AssertFullSemver ( "1.3.0-alpha.2" , configuration ) ;
93+
94+ fixture . Checkout ( feature2Branch ) ;
95+ fixture . AssertFullSemver (
96+ "1.3.0-f2.1+0" ,
97+ configuration ,
98+ customMessage :
99+ "Feature branches use inherited versioning (increment: inherit), " + System . Environment . NewLine +
100+ "and your config inherits from develop." + System . Environment . NewLine + System . Environment . NewLine +
101+ "GitVersion uses the merge base between the feature and develop to determine the version." + System . Environment . NewLine + System . Environment . NewLine +
102+ "As develop progresses (e.g., by releasing 1.2.0), rebuilding old feature branches can" + System . Environment . NewLine +
103+ "produce different versions." ) ;
104+
105+ fullSemver = "1.3.0-f2.1+1" ;
106+ fixture . MakeACommit (
107+ "feature 2 additional commit after original feature has been merged to develop " + System . Environment . NewLine +
108+ $ "and release/1.2.0 has already happened >> { fullSemver } " +
109+ "Problem #1: 1.3.0-f2.1+0 is what I observe when I run dotnet-gitversion 6.3.0 but in the repo the assertion is 1.3.0-f2.1+1" +
110+ "After rebase 1.3.0-f2.1+3 is both what the test asserts and what I observe when I run dotnet-gitversion 6.3.0." +
111+ "Problem #2: I expected to get the same before and after the rebase." +
112+ "" +
113+ "Whether my expectations are correct or not could we at least build upon the documentation I have started to add " +
114+ "as an explanation of observed behaviour. I'm happy to translate an explanation in to test " +
115+ "documentation if you confirm it would be accepted on PR."
116+ ) ;
117+
118+ var identity = new Identity (
119+ fixture . Repository . Head . Tip . Committer . Name ,
120+ fixture . Repository . Head . Tip . Committer . Email ) ;
121+ fixture . AssertFullSemver ( fullSemver , configuration ) ;
122+ var rebaseResult = fixture . Repository . Rebase . Start (
123+ fixture . Repository . Branches [ feature2Branch ] ,
124+ fixture . Repository . Branches [ developBranch ] ,
125+ fixture . Repository . Branches [ developBranch ] ,
126+ identity ,
127+ new RebaseOptions ( ) ) ;
128+ while ( rebaseResult != null && rebaseResult . Status != RebaseStatus . Complete )
129+ {
130+ rebaseResult = fixture . Repository . Rebase . Continue ( identity , new RebaseOptions ( ) ) ;
131+ }
132+
133+ fixture . AssertFullSemver ( fullSemver , configuration , customMessage : "I expected to get the same before and after the rebase." ) ;
134+
135+ void initialMainAction ( IRepository r )
136+ {
137+ if ( configuration is GitVersionConfiguration concreteConfig )
138+ {
139+ var yaml = new ConfigurationSerializer ( ) . Serialize ( concreteConfig ) ;
140+ const string fileName = "GitVersion.yml" ;
141+ var filePath = FileSystemHelper . Path . Combine ( r . Info . Path , ".." , fileName ) ;
142+ File . WriteAllText ( filePath , yaml ) ;
143+ r . Index . Add ( fileName ) ;
144+ r . Index . Write ( ) ;
145+ }
146+
147+ r . MakeATaggedCommit ( "1.0.0" , $ "Initial commit on { MainBranch } ") ;
148+ }
83149 }
84150}
0 commit comments