@@ -40,6 +40,7 @@ type testRepo struct {
40
40
firstCommit string
41
41
firstBranchCommit string
42
42
secondBranchCommit string
43
+ thirdBranchCommit string
43
44
branchName string
44
45
firstTagCommit string
45
46
firstTagName string
@@ -52,6 +53,11 @@ type testRepo struct {
52
53
53
54
// newTestRepo creates a test repo with the following structure:
54
55
//
56
+ // * commit `thirdBranchCommit` (HEAD -> `branchName`, origin/`branchName`)
57
+ // | Author: John Doe <[email protected] >
58
+ // |
59
+ // | Fourth commit
60
+ // |
55
61
// * commit `secondBranchCommit` (tag: `thirdTagName`, HEAD -> `branchName`, origin/`branchName`)
56
62
// | Author: John Doe <[email protected] >
57
63
// |
@@ -159,7 +165,7 @@ func newTestRepo(t *testing.T) *testRepo {
159
165
})
160
166
require .Nil (t , err )
161
167
162
- thirdTagName := "v0.1.2 "
168
+ thirdTagName := "v1.17.1 "
163
169
thirdTagRef , err := cloneRepo .CreateTag (thirdTagName , secondBranchCommit ,
164
170
& gogit.CreateTagOptions {
165
171
Tagger : author ,
@@ -168,6 +174,21 @@ func newTestRepo(t *testing.T) *testRepo {
168
174
)
169
175
require .Nil (t , err )
170
176
177
+ const thirdBranchTestFileName = "branch-test-file-3"
178
+ require .Nil (t , ioutil .WriteFile (
179
+ filepath .Join (cloneTempDir , thirdBranchTestFileName ),
180
+ []byte ("test-content" ),
181
+ os .FileMode (0644 ),
182
+ ))
183
+ _ , err = worktree .Add (thirdBranchTestFileName )
184
+ require .Nil (t , err )
185
+
186
+ thirdBranchCommit , err := worktree .Commit ("Fourth commit" , & gogit.CommitOptions {
187
+ Author : author ,
188
+ All : true ,
189
+ })
190
+ require .Nil (t , err )
191
+
171
192
// Push the test content into the bare repo
172
193
_ , err = cloneRepo .CreateRemote (& config.RemoteConfig {
173
194
Name : git .DefaultRemote ,
@@ -194,6 +215,7 @@ func newTestRepo(t *testing.T) *testRepo {
194
215
firstCommit : firstCommit .String (),
195
216
firstBranchCommit : firstBranchCommit .String (),
196
217
secondBranchCommit : secondBranchCommit .String (),
218
+ thirdBranchCommit : thirdBranchCommit .String (),
197
219
branchName : branchName ,
198
220
firstTagName : firstTagName ,
199
221
firstTagCommit : firstTagRef .Hash ().String (),
@@ -270,7 +292,7 @@ func TestSuccessHead(t *testing.T) {
270
292
271
293
head , err := testRepo .sut .Head ()
272
294
require .Nil (t , err )
273
- require .Equal (t , head , testRepo .secondBranchCommit )
295
+ require .Equal (t , head , testRepo .thirdBranchCommit )
274
296
}
275
297
276
298
func TestSuccessMerge (t * testing.T ) {
@@ -308,7 +330,7 @@ func TestSuccessRevParse(t *testing.T) {
308
330
309
331
branchRev , err := testRepo .sut .RevParse (testRepo .branchName )
310
332
require .Nil (t , err )
311
- require .Equal (t , branchRev , testRepo .secondBranchCommit )
333
+ require .Equal (t , branchRev , testRepo .thirdBranchCommit )
312
334
313
335
tagRev , err := testRepo .sut .RevParse (testRepo .firstTagName )
314
336
require .Nil (t , err )
@@ -333,7 +355,7 @@ func TestSuccessRevParseShort(t *testing.T) {
333
355
334
356
branchRev , err := testRepo .sut .RevParseShort (testRepo .branchName )
335
357
require .Nil (t , err )
336
- require .Equal (t , branchRev , testRepo .secondBranchCommit [:10 ])
358
+ require .Equal (t , branchRev , testRepo .thirdBranchCommit [:10 ])
337
359
338
360
tagRev , err := testRepo .sut .RevParseShort (testRepo .firstTagName )
339
361
require .Nil (t , err )
@@ -386,6 +408,15 @@ func TestSuccessLatestTagForBranch(t *testing.T) {
386
408
require .Equal (t , util .SemverToTagString (version ), testRepo .firstTagName )
387
409
}
388
410
411
+ func TestSuccessLatestTagForBranchRelease (t * testing.T ) {
412
+ testRepo := newTestRepo (t )
413
+ defer testRepo .cleanup (t )
414
+
415
+ version , err := testRepo .sut .LatestTagForBranch ("release-1.17" )
416
+ require .Nil (t , err )
417
+ require .Equal (t , util .SemverToTagString (version ), testRepo .thirdTagName )
418
+ }
419
+
389
420
func TestFailureLatestTagForBranchInvalidBranch (t * testing.T ) {
390
421
testRepo := newTestRepo (t )
391
422
defer testRepo .cleanup (t )
@@ -399,15 +430,28 @@ func TestSuccessLatestPatchToPatch(t *testing.T) {
399
430
testRepo := newTestRepo (t )
400
431
defer testRepo .cleanup (t )
401
432
402
- nextMinorTag := "v1.17.1"
433
+ // This test case gets commits from v1.17.0 to v1.17.1
434
+ result , err := testRepo .sut .LatestPatchToPatch (testRepo .branchName )
435
+ require .Nil (t , err )
436
+ require .Equal (t , result .StartSHA (), testRepo .firstCommit )
437
+ require .Equal (t , result .StartRev (), testRepo .firstTagName )
438
+ require .Equal (t , result .EndRev (), testRepo .thirdTagName )
439
+ }
440
+
441
+ func TestSuccessLatestPatchToPatchNewTag (t * testing.T ) {
442
+ testRepo := newTestRepo (t )
443
+ defer testRepo .cleanup (t )
444
+
445
+ // This test case gets commits from v1.17.1 to a new v1.17.2
446
+ nextMinorTag := "v1.17.2"
403
447
require .Nil (t , command .NewWithWorkDir (
404
448
testRepo .sut .Dir (), "git" , "tag" , nextMinorTag ,
405
449
).RunSuccess ())
406
450
407
451
result , err := testRepo .sut .LatestPatchToPatch (testRepo .branchName )
408
452
require .Nil (t , err )
409
- require .Equal (t , result .StartSHA (), testRepo .firstCommit )
410
- require .Equal (t , result .StartRev (), testRepo .firstTagName )
453
+ require .Equal (t , result .StartSHA (), testRepo .secondBranchCommit )
454
+ require .Equal (t , result .StartRev (), testRepo .thirdTagName )
411
455
require .Equal (t , result .EndRev (), nextMinorTag )
412
456
}
413
457
@@ -420,6 +464,18 @@ func TestFailureLatestPatchToPatchWrongBranch(t *testing.T) {
420
464
require .Equal (t , git.DiscoverResult {}, result )
421
465
}
422
466
467
+ func TestSuccessLatestPatchToLatest (t * testing.T ) {
468
+ testRepo := newTestRepo (t )
469
+ defer testRepo .cleanup (t )
470
+
471
+ // This test case gets commits from v1.17.1 to head of release-1.17
472
+ result , err := testRepo .sut .LatestPatchToLatest (testRepo .branchName )
473
+ require .Nil (t , err )
474
+ require .Equal (t , result .StartSHA (), testRepo .secondBranchCommit )
475
+ require .Equal (t , result .StartRev (), testRepo .thirdTagName )
476
+ require .Equal (t , result .EndSHA (), testRepo .thirdBranchCommit )
477
+ }
478
+
423
479
func TestSuccessDry (t * testing.T ) {
424
480
testRepo := newTestRepo (t )
425
481
defer testRepo .cleanup (t )
@@ -496,8 +552,8 @@ func TestTagsForBranchOnBranch(t *testing.T) {
496
552
result , err := testRepo .sut .TagsForBranch (testRepo .branchName )
497
553
require .Nil (t , err )
498
554
require .Equal (t , result , []string {
499
- testRepo .firstTagName ,
500
555
testRepo .thirdTagName ,
556
+ testRepo .firstTagName ,
501
557
testRepo .secondTagName ,
502
558
})
503
559
}
0 commit comments