11using GitVersion . Configuration ;
22using GitVersion . Core . Tests . Helpers ;
33using GitVersion . Helpers ;
4+ using GitVersion . Logging ;
45using LibGit2Sharp ;
6+ using Microsoft . Extensions . DependencyInjection ;
57
68namespace GitVersion . Core . Tests . IntegrationTests ;
79
810[ TestFixture ]
911public class GitflowScenarios : TestBase
1012{
13+ private readonly ILog log ;
14+
15+ public GitflowScenarios ( )
16+ {
17+ var sp = ConfigureServices ( ) ;
18+ this . log = sp . GetRequiredService < ILog > ( ) ;
19+ }
20+
1121 [ Test ]
1222 public void GitflowComplexExample ( )
1323 {
@@ -21,111 +31,133 @@ public void GitflowComplexExample()
2131
2232 var configuration = GitFlowConfigurationBuilder . New . Build ( ) ;
2333
24- using var fixture = new BaseGitFlowRepositoryFixture ( initialMainAction , deleteOnDispose : false ) ;
34+ using var fixture = new BaseGitFlowRepositoryFixture ( InitialMainAction , deleteOnDispose : false ) ;
2535 var fullSemver = "1.1.0-alpha.1" ;
2636 fixture . AssertFullSemver ( fullSemver , configuration ) ;
37+ fixture . AssertCommitsSinceVersionSource ( 1 , configuration ) ;
2738
2839 // Feature 1
2940 fixture . BranchTo ( feature1Branch ) ;
3041
3142 fixture . MakeACommit ( $ "added feature 1 >> { fullSemver } ") ;
3243 fullSemver = "1.1.0-f1.1+2" ;
3344 fixture . AssertFullSemver ( fullSemver , configuration ) ;
45+ fixture . AssertCommitsSinceVersionSource ( 2 , configuration ) ;
3446 fixture . Checkout ( developBranch ) ;
3547 fixture . MergeNoFF ( feature1Branch ) ;
3648 if ( ! keepBranches ) fixture . Repository . Branches . Remove ( fixture . Repository . Branches [ feature1Branch ] ) ;
3749 fixture . AssertFullSemver ( "1.1.0-alpha.3" , configuration ) ;
50+ fixture . AssertCommitsSinceVersionSource ( 3 , configuration ) ;
3851
3952 // Release 1.1.0
4053 fixture . BranchTo ( release1Branch ) ;
4154 fixture . MakeACommit ( "release stabilization" ) ;
4255 fixture . AssertFullSemver ( "1.1.0-beta.1+4" , configuration ) ;
56+ fixture . AssertCommitsSinceVersionSource ( 4 , configuration ) ;
4357 fixture . Checkout ( MainBranch ) ;
4458 fixture . MergeNoFF ( release1Branch ) ;
4559 fixture . AssertFullSemver ( "1.1.0-5" , configuration ) ;
60+ fixture . AssertCommitsSinceVersionSource ( 5 , configuration ) ;
4661 fixture . ApplyTag ( "1.1.0" ) ;
4762 fixture . AssertFullSemver ( "1.1.0" , configuration ) ;
63+ fixture . AssertCommitsSinceVersionSource ( 0 , configuration ) ;
4864 fixture . Checkout ( developBranch ) ;
4965 fixture . MergeNoFF ( release1Branch ) ;
5066 fixture . Repository . Branches . Remove ( fixture . Repository . Branches [ release1Branch ] ) ;
5167 fixture . AssertFullSemver ( "1.2.0-alpha.1" , configuration ) ;
68+ fixture . AssertCommitsSinceVersionSource ( 1 , configuration ) ;
5269
5370 // Feature 2
5471 fixture . BranchTo ( feature2Branch ) ;
5572 fullSemver = "1.2.0-f2.1+2" ;
5673 fixture . MakeACommit ( $ "added feature 2 >> { fullSemver } ") ;
5774 fixture . AssertFullSemver ( fullSemver , configuration ) ;
75+ fixture . AssertCommitsSinceVersionSource ( 2 , configuration ) ;
5876 fixture . Checkout ( developBranch ) ;
5977 fixture . MergeNoFF ( feature2Branch ) ;
6078 if ( ! keepBranches ) fixture . Repository . Branches . Remove ( fixture . Repository . Branches [ feature2Branch ] ) ;
6179 fixture . AssertFullSemver ( "1.2.0-alpha.3" , configuration ) ;
80+ fixture . AssertCommitsSinceVersionSource ( 3 , configuration ) ;
6281
6382 // Release 1.2.0
6483 fixture . BranchTo ( release2Branch ) ;
6584 fullSemver = "1.2.0-beta.1+8" ;
6685 fixture . MakeACommit ( $ "release stabilization >> { fullSemver } ") ;
6786 fixture . AssertFullSemver ( fullSemver , configuration ) ;
87+ fixture . AssertCommitsSinceVersionSource ( 8 , configuration ) ;
6888 fixture . Checkout ( MainBranch ) ;
6989 fixture . MergeNoFF ( release2Branch ) ;
7090 fixture . AssertFullSemver ( "1.2.0-5" , configuration ) ;
91+ fixture . AssertCommitsSinceVersionSource ( 5 , configuration ) ;
7192 fixture . ApplyTag ( "1.2.0" ) ;
7293 fixture . AssertFullSemver ( "1.2.0" , configuration ) ;
94+ fixture . AssertCommitsSinceVersionSource ( 0 , configuration ) ;
7395 fixture . Checkout ( developBranch ) ;
7496 fixture . MergeNoFF ( release2Branch ) ;
7597 if ( ! keepBranches )
7698 {
7799 fixture . Repository . Branches . Remove ( fixture . Repository . Branches [ release2Branch ] ) ;
78100 }
79101 fixture . AssertFullSemver ( "1.3.0-alpha.1" , configuration ) ;
102+ fixture . AssertCommitsSinceVersionSource ( 1 , configuration ) ;
80103
81104 // Hotfix
82105 fixture . Checkout ( MainBranch ) ;
83106 fixture . BranchTo ( hotfixBranch ) ;
84107 fullSemver = "1.2.1-beta.1+1" ;
85108 fixture . MakeACommit ( $ "added hotfix >> { fullSemver } ") ;
86109 fixture . AssertFullSemver ( fullSemver , configuration ) ;
110+ fixture . AssertCommitsSinceVersionSource ( 1 , configuration ) ;
87111 fixture . Checkout ( MainBranch ) ;
88112 fixture . MergeNoFF ( hotfixBranch ) ;
89113 fixture . AssertFullSemver ( "1.2.1-2" , configuration ) ;
114+ fixture . AssertCommitsSinceVersionSource ( 2 , configuration ) ;
90115 fixture . ApplyTag ( "1.2.1" ) ;
91116 fixture . AssertFullSemver ( "1.2.1" , configuration ) ;
92- fixture . AssertCommitsSinceVersionSource ( 2 , configuration ) ;
117+ fixture . AssertCommitsSinceVersionSource ( 0 , configuration ) ;
93118 fixture . Checkout ( developBranch ) ;
94119 fixture . MergeNoFF ( hotfixBranch ) ;
95120 if ( ! keepBranches )
96121 {
97122 fixture . Repository . Branches . Remove ( fixture . Repository . Branches [ hotfixBranch ] ) ;
98123 }
99124 fixture . AssertFullSemver ( "1.3.0-alpha.2" , configuration ) ;
125+ fixture . AssertCommitsSinceVersionSource ( 2 , configuration ) ;
100126
101127 fixture . Checkout ( feature2Branch ) ;
102- fixture . AssertFullSemver (
103- "1.3.0-f2.1+0" ,
104- configuration ,
105- customMessage :
106- "Feature branches use inherited versioning (increment: inherit), " + System . Environment . NewLine +
107- "and your config inherits from develop." + System . Environment . NewLine + System . Environment . NewLine +
128+ fixture . SequenceDiagram . NoteOver ( $ "Checkout { feature2Branch } ", feature2Branch ) ;
129+ fixture . AssertFullSemver ( "1.3.0-f2.1+0" , configuration ) ;
130+ fixture . SequenceDiagram . NoteOver (
131+ string . Join ( System . Environment . NewLine , ( "Feature branches are configured to inherit version (increment: inherit)." + System . Environment . NewLine + System . Environment . NewLine +
108132 "GitVersion uses the merge base between the feature and develop to determine the version." + System . Environment . NewLine + System . Environment . NewLine +
109- "As develop progresses (e.g., by releasing 1.2.0), rebuilding old feature branches can" + System . Environment . NewLine +
110- "produce different versions." ) ;
133+ "As develop progresses (e.g., by releasing 1.2.0 & 1.2.1), rebuilding old feature branches can produce different versions." + System . Environment . NewLine + System . Environment . NewLine +
134+ "Here we've checked out commit H again and now it's it's own VersionSource and produces 1.3.0-f2.1+0" ) . SplitIntoLines ( 60 ) ) , feature2Branch ) ;
135+ fixture . AssertCommitsSinceVersionSource ( 0 , configuration ) ;
111136
112137 fullSemver = "1.3.0-f2.1+1" ;
113138 fixture . MakeACommit (
114139 "feature 2 additional commit after original feature has been merged to develop " + System . Environment . NewLine +
115- $ "and release/1.2.0 has already happened >> { fullSemver } " +
116- "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" +
117- "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." +
118- "Problem #2: I expected to get the same before and after the rebase." +
119- "" +
120- "Whether my expectations are correct or not could we at least build upon the documentation I have started to add " +
121- "as an explanation of observed behaviour. I'm happy to translate an explanation in to test " +
122- "documentation if you confirm it would be accepted on PR."
140+ $ "and release/1.2.0 has already happened >> { fullSemver } "
123141 ) ;
142+ fixture . AssertFullSemver ( fullSemver , configuration ) ;
143+ fixture . AssertCommitsSinceVersionSource ( 1 , configuration ) ;
144+ fixture . SequenceDiagram . NoteOver (
145+ string . Join ( System . Environment . NewLine , ( $ "We committed again to { feature2Branch } ." + System . Environment . NewLine + System . Environment . NewLine +
146+ "Why is the VersionSource no longer H but has instead jumped to N?" + System . Environment . NewLine + System . Environment . NewLine +
147+ $ "I expected this to produce { fullSemver } and it does.") . SplitIntoLines ( 60 ) ) , feature2Branch ) ;
148+
149+ var gitRepository = fixture . Repository . ToGitRepository ( ) ;
150+ var gitRepoMetadataProvider = new RepositoryStore ( this . log , gitRepository ) ;
151+ // H can't be it's own ancestor, so merge base is G
152+ fixture . SequenceDiagram . GetOrAddLabel ( gitRepoMetadataProvider . FindMergeBase ( gitRepository . Branches [ feature2Branch ] , gitRepository . Branches [ developBranch ] ) . Sha ) . ShouldBe ( "G" ) ;
153+ fixture . SequenceDiagram . GetOrAddLabel ( gitRepoMetadataProvider . FindMergeBase ( gitRepository . Branches [ feature2Branch ] , gitRepository . Branches [ MainBranch ] ) . Sha ) . ShouldBe ( "G" ) ;
154+ // Why is H it's own VersionSource though if after committing with H as the ancestor we get N as the VersionSource?
155+
156+ fixture . SequenceDiagram . NoteOver ( $ "Now we rebase { feature2Branch } onto { developBranch } ", feature2Branch ) ;
124157
125158 var identity = new Identity (
126159 fixture . Repository . Head . Tip . Committer . Name ,
127160 fixture . Repository . Head . Tip . Committer . Email ) ;
128- fixture . AssertFullSemver ( fullSemver , configuration ) ;
129161 var rebaseResult = fixture . Repository . Rebase . Start (
130162 fixture . Repository . Branches [ feature2Branch ] ,
131163 fixture . Repository . Branches [ developBranch ] ,
@@ -137,9 +169,14 @@ public void GitflowComplexExample()
137169 rebaseResult = fixture . Repository . Rebase . Continue ( identity , new RebaseOptions ( ) ) ;
138170 }
139171
140- fixture . AssertFullSemver ( fullSemver , configuration , customMessage : "I expected to get the same before and after the rebase." ) ;
172+ fullSemver = "1.3.0-f2.1+3" ;
173+ fixture . AssertFullSemver ( fullSemver , configuration ) ;
174+ fixture . AssertCommitsSinceVersionSource ( 3 , configuration ) ;
175+ fixture . SequenceDiagram . NoteOver (
176+ string . Join ( System . Environment . NewLine , $ "Post rebase the VersionSource is again N - the last commit on { MainBranch } ." + System . Environment . NewLine + System . Environment . NewLine +
177+ $ "I expected this to produce 1.3.0-f2.1+1 and have a VersionSource of O with self as one commit since VersionSource. Instead VersionSource of N produces { fullSemver } , with a count traversal that includes both L and O!". SplitIntoLines ( 60 ) ) , feature2Branch ) ;
141178
142- void initialMainAction ( IRepository r )
179+ void InitialMainAction ( IRepository r )
143180 {
144181 if ( configuration is GitVersionConfiguration concreteConfig )
145182 {
0 commit comments