1
1
using GitVersion . Configuration ;
2
2
using GitVersion . Core . Tests . Helpers ;
3
3
using GitVersion . Helpers ;
4
+ using GitVersion . Logging ;
4
5
using LibGit2Sharp ;
6
+ using Microsoft . Extensions . DependencyInjection ;
5
7
6
8
namespace GitVersion . Core . Tests . IntegrationTests ;
7
9
8
10
[ TestFixture ]
9
11
public class GitflowScenarios : TestBase
10
12
{
13
+ private readonly ILog log ;
14
+
15
+ public GitflowScenarios ( )
16
+ {
17
+ var sp = ConfigureServices ( ) ;
18
+ this . log = sp . GetRequiredService < ILog > ( ) ;
19
+ }
20
+
11
21
[ Test ]
12
22
public void GitflowComplexExample ( )
13
23
{
@@ -21,111 +31,133 @@ public void GitflowComplexExample()
21
31
22
32
var configuration = GitFlowConfigurationBuilder . New . Build ( ) ;
23
33
24
- using var fixture = new BaseGitFlowRepositoryFixture ( initialMainAction , deleteOnDispose : false ) ;
34
+ using var fixture = new BaseGitFlowRepositoryFixture ( InitialMainAction , deleteOnDispose : false ) ;
25
35
var fullSemver = "1.1.0-alpha.1" ;
26
36
fixture . AssertFullSemver ( fullSemver , configuration ) ;
37
+ fixture . AssertCommitsSinceVersionSource ( 1 , configuration ) ;
27
38
28
39
// Feature 1
29
40
fixture . BranchTo ( feature1Branch ) ;
30
41
31
42
fixture . MakeACommit ( $ "added feature 1 >> { fullSemver } ") ;
32
43
fullSemver = "1.1.0-f1.1+2" ;
33
44
fixture . AssertFullSemver ( fullSemver , configuration ) ;
45
+ fixture . AssertCommitsSinceVersionSource ( 2 , configuration ) ;
34
46
fixture . Checkout ( developBranch ) ;
35
47
fixture . MergeNoFF ( feature1Branch ) ;
36
48
if ( ! keepBranches ) fixture . Repository . Branches . Remove ( fixture . Repository . Branches [ feature1Branch ] ) ;
37
49
fixture . AssertFullSemver ( "1.1.0-alpha.3" , configuration ) ;
50
+ fixture . AssertCommitsSinceVersionSource ( 3 , configuration ) ;
38
51
39
52
// Release 1.1.0
40
53
fixture . BranchTo ( release1Branch ) ;
41
54
fixture . MakeACommit ( "release stabilization" ) ;
42
55
fixture . AssertFullSemver ( "1.1.0-beta.1+4" , configuration ) ;
56
+ fixture . AssertCommitsSinceVersionSource ( 4 , configuration ) ;
43
57
fixture . Checkout ( MainBranch ) ;
44
58
fixture . MergeNoFF ( release1Branch ) ;
45
59
fixture . AssertFullSemver ( "1.1.0-5" , configuration ) ;
60
+ fixture . AssertCommitsSinceVersionSource ( 5 , configuration ) ;
46
61
fixture . ApplyTag ( "1.1.0" ) ;
47
62
fixture . AssertFullSemver ( "1.1.0" , configuration ) ;
63
+ fixture . AssertCommitsSinceVersionSource ( 0 , configuration ) ;
48
64
fixture . Checkout ( developBranch ) ;
49
65
fixture . MergeNoFF ( release1Branch ) ;
50
66
fixture . Repository . Branches . Remove ( fixture . Repository . Branches [ release1Branch ] ) ;
51
67
fixture . AssertFullSemver ( "1.2.0-alpha.1" , configuration ) ;
68
+ fixture . AssertCommitsSinceVersionSource ( 1 , configuration ) ;
52
69
53
70
// Feature 2
54
71
fixture . BranchTo ( feature2Branch ) ;
55
72
fullSemver = "1.2.0-f2.1+2" ;
56
73
fixture . MakeACommit ( $ "added feature 2 >> { fullSemver } ") ;
57
74
fixture . AssertFullSemver ( fullSemver , configuration ) ;
75
+ fixture . AssertCommitsSinceVersionSource ( 2 , configuration ) ;
58
76
fixture . Checkout ( developBranch ) ;
59
77
fixture . MergeNoFF ( feature2Branch ) ;
60
78
if ( ! keepBranches ) fixture . Repository . Branches . Remove ( fixture . Repository . Branches [ feature2Branch ] ) ;
61
79
fixture . AssertFullSemver ( "1.2.0-alpha.3" , configuration ) ;
80
+ fixture . AssertCommitsSinceVersionSource ( 3 , configuration ) ;
62
81
63
82
// Release 1.2.0
64
83
fixture . BranchTo ( release2Branch ) ;
65
84
fullSemver = "1.2.0-beta.1+8" ;
66
85
fixture . MakeACommit ( $ "release stabilization >> { fullSemver } ") ;
67
86
fixture . AssertFullSemver ( fullSemver , configuration ) ;
87
+ fixture . AssertCommitsSinceVersionSource ( 8 , configuration ) ;
68
88
fixture . Checkout ( MainBranch ) ;
69
89
fixture . MergeNoFF ( release2Branch ) ;
70
90
fixture . AssertFullSemver ( "1.2.0-5" , configuration ) ;
91
+ fixture . AssertCommitsSinceVersionSource ( 5 , configuration ) ;
71
92
fixture . ApplyTag ( "1.2.0" ) ;
72
93
fixture . AssertFullSemver ( "1.2.0" , configuration ) ;
94
+ fixture . AssertCommitsSinceVersionSource ( 0 , configuration ) ;
73
95
fixture . Checkout ( developBranch ) ;
74
96
fixture . MergeNoFF ( release2Branch ) ;
75
97
if ( ! keepBranches )
76
98
{
77
99
fixture . Repository . Branches . Remove ( fixture . Repository . Branches [ release2Branch ] ) ;
78
100
}
79
101
fixture . AssertFullSemver ( "1.3.0-alpha.1" , configuration ) ;
102
+ fixture . AssertCommitsSinceVersionSource ( 1 , configuration ) ;
80
103
81
104
// Hotfix
82
105
fixture . Checkout ( MainBranch ) ;
83
106
fixture . BranchTo ( hotfixBranch ) ;
84
107
fullSemver = "1.2.1-beta.1+1" ;
85
108
fixture . MakeACommit ( $ "added hotfix >> { fullSemver } ") ;
86
109
fixture . AssertFullSemver ( fullSemver , configuration ) ;
110
+ fixture . AssertCommitsSinceVersionSource ( 1 , configuration ) ;
87
111
fixture . Checkout ( MainBranch ) ;
88
112
fixture . MergeNoFF ( hotfixBranch ) ;
89
113
fixture . AssertFullSemver ( "1.2.1-2" , configuration ) ;
114
+ fixture . AssertCommitsSinceVersionSource ( 2 , configuration ) ;
90
115
fixture . ApplyTag ( "1.2.1" ) ;
91
116
fixture . AssertFullSemver ( "1.2.1" , configuration ) ;
92
- fixture . AssertCommitsSinceVersionSource ( 2 , configuration ) ;
117
+ fixture . AssertCommitsSinceVersionSource ( 0 , configuration ) ;
93
118
fixture . Checkout ( developBranch ) ;
94
119
fixture . MergeNoFF ( hotfixBranch ) ;
95
120
if ( ! keepBranches )
96
121
{
97
122
fixture . Repository . Branches . Remove ( fixture . Repository . Branches [ hotfixBranch ] ) ;
98
123
}
99
124
fixture . AssertFullSemver ( "1.3.0-alpha.2" , configuration ) ;
125
+ fixture . AssertCommitsSinceVersionSource ( 2 , configuration ) ;
100
126
101
127
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 +
108
132
"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 ) ;
111
136
112
137
fullSemver = "1.3.0-f2.1+1" ;
113
138
fixture . MakeACommit (
114
139
"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 } "
123
141
) ;
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 ) ;
124
157
125
158
var identity = new Identity (
126
159
fixture . Repository . Head . Tip . Committer . Name ,
127
160
fixture . Repository . Head . Tip . Committer . Email ) ;
128
- fixture . AssertFullSemver ( fullSemver , configuration ) ;
129
161
var rebaseResult = fixture . Repository . Rebase . Start (
130
162
fixture . Repository . Branches [ feature2Branch ] ,
131
163
fixture . Repository . Branches [ developBranch ] ,
@@ -137,9 +169,14 @@ public void GitflowComplexExample()
137
169
rebaseResult = fixture . Repository . Rebase . Continue ( identity , new RebaseOptions ( ) ) ;
138
170
}
139
171
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 ) ;
141
178
142
- void initialMainAction ( IRepository r )
179
+ void InitialMainAction ( IRepository r )
143
180
{
144
181
if ( configuration is GitVersionConfiguration concreteConfig )
145
182
{
0 commit comments