1
1
using GitVersion . Configuration ;
2
2
using GitVersion . Core . Tests . Helpers ;
3
+ using GitVersion . Helpers ;
4
+ using LibGit2Sharp ;
3
5
4
6
namespace GitVersion . Core . Tests . IntegrationTests ;
5
7
@@ -9,24 +11,29 @@ public class GitflowScenarios : TestBase
9
11
[ Test ]
10
12
public void GitflowComplexExample ( )
11
13
{
14
+ var keepBranches = true ;
12
15
const string developBranch = "develop" ;
13
16
const string feature1Branch = "feature/f1" ;
14
17
const string feature2Branch = "feature/f2" ;
15
18
const string release1Branch = "release/1.1.0" ;
16
19
const string release2Branch = "release/1.2.0" ;
17
20
const string hotfixBranch = "hotfix/hf" ;
21
+
18
22
var configuration = GitFlowConfigurationBuilder . New . Build ( ) ;
19
23
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 ) ;
22
27
23
28
// Feature 1
24
29
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 ) ;
27
34
fixture . Checkout ( developBranch ) ;
28
35
fixture . MergeNoFF ( feature1Branch ) ;
29
- fixture . Repository . Branches . Remove ( fixture . Repository . Branches [ feature1Branch ] ) ;
36
+ if ( ! keepBranches ) fixture . Repository . Branches . Remove ( fixture . Repository . Branches [ feature1Branch ] ) ;
30
37
fixture . AssertFullSemver ( "1.1.0-alpha.3" , configuration ) ;
31
38
32
39
// Release 1.1.0
@@ -45,40 +52,99 @@ public void GitflowComplexExample()
45
52
46
53
// Feature 2
47
54
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 ) ;
50
58
fixture . Checkout ( developBranch ) ;
51
59
fixture . MergeNoFF ( feature2Branch ) ;
52
- fixture . Repository . Branches . Remove ( fixture . Repository . Branches [ feature2Branch ] ) ;
60
+ if ( ! keepBranches ) fixture . Repository . Branches . Remove ( fixture . Repository . Branches [ feature2Branch ] ) ;
53
61
fixture . AssertFullSemver ( "1.2.0-alpha.3" , configuration ) ;
54
62
55
63
// Release 1.2.0
56
64
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 ) ;
59
68
fixture . Checkout ( MainBranch ) ;
60
69
fixture . MergeNoFF ( release2Branch ) ;
61
70
fixture . AssertFullSemver ( "1.2.0-5" , configuration ) ;
62
71
fixture . ApplyTag ( "1.2.0" ) ;
63
72
fixture . AssertFullSemver ( "1.2.0" , configuration ) ;
64
73
fixture . Checkout ( developBranch ) ;
65
74
fixture . MergeNoFF ( release2Branch ) ;
66
- fixture . Repository . Branches . Remove ( fixture . Repository . Branches [ release2Branch ] ) ;
75
+ if ( ! keepBranches ) fixture . Repository . Branches . Remove ( fixture . Repository . Branches [ release2Branch ] ) ;
67
76
fixture . AssertFullSemver ( "1.3.0-alpha.1" , configuration ) ;
68
77
69
78
// Hotfix
70
79
fixture . Checkout ( MainBranch ) ;
71
80
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 ) ;
74
84
fixture . Checkout ( MainBranch ) ;
75
85
fixture . MergeNoFF ( hotfixBranch ) ;
76
86
fixture . AssertFullSemver ( "1.2.1-2" , configuration ) ;
77
87
fixture . ApplyTag ( "1.2.1" ) ;
78
88
fixture . AssertFullSemver ( "1.2.1" , configuration ) ;
79
89
fixture . Checkout ( developBranch ) ;
80
90
fixture . MergeNoFF ( hotfixBranch ) ;
81
- fixture . Repository . Branches . Remove ( fixture . Repository . Branches [ hotfixBranch ] ) ;
91
+ if ( ! keepBranches ) fixture . Repository . Branches . Remove ( fixture . Repository . Branches [ hotfixBranch ] ) ;
82
92
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
+ }
83
149
}
84
150
}
0 commit comments