@@ -394,16 +394,25 @@ void main() {
394
394
const String hash = 'abcdef' ;
395
395
GitTagVersion gitTagVersion;
396
396
397
- // legacy tag format (x.y.z-dev.m.n), master channel
398
- gitTagVersion = GitTagVersion .parse ('1.2.3-dev. 4.5-4 -g$hash ' );
399
- expect (gitTagVersion.frameworkVersionFor (hash), '1.2.3-5.0.pre.4 ' );
400
- expect (gitTagVersion.gitTag, '1.2.3-dev. 4.5' );
397
+ // Master channel
398
+ gitTagVersion = GitTagVersion .parse ('1.2.3-4.5.pre-13 -g$hash ' );
399
+ expect (gitTagVersion.frameworkVersionFor (hash), '1.2.3-5.0.pre.13 ' );
400
+ expect (gitTagVersion.gitTag, '1.2.3-4.5.pre ' );
401
401
expect (gitTagVersion.devVersion, 4 );
402
402
expect (gitTagVersion.devPatch, 5 );
403
403
404
- // new tag release format, master channel
405
- gitTagVersion = GitTagVersion .parse ('1.2.3-4.5.pre-13-g$hash ' );
406
- expect (gitTagVersion.frameworkVersionFor (hash), '1.2.3-5.0.pre.13' );
404
+ // Stable channel
405
+ gitTagVersion = GitTagVersion .parse ('1.2.3' );
406
+ expect (gitTagVersion.frameworkVersionFor (hash), '1.2.3' );
407
+ expect (gitTagVersion.x, 1 );
408
+ expect (gitTagVersion.y, 2 );
409
+ expect (gitTagVersion.z, 3 );
410
+ expect (gitTagVersion.devVersion, null );
411
+ expect (gitTagVersion.devPatch, null );
412
+
413
+ // Dev channel
414
+ gitTagVersion = GitTagVersion .parse ('1.2.3-4.5.pre' );
415
+ expect (gitTagVersion.frameworkVersionFor (hash), '1.2.3-4.5.pre' );
407
416
expect (gitTagVersion.gitTag, '1.2.3-4.5.pre' );
408
417
expect (gitTagVersion.devVersion, 4 );
409
418
expect (gitTagVersion.devPatch, 5 );
@@ -448,6 +457,29 @@ void main() {
448
457
);
449
458
});
450
459
460
+ testUsingContext ('determine favors stable tags over dev tags' , () {
461
+ final MockProcessUtils mockProcessUtils = MockProcessUtils ();
462
+ when (mockProcessUtils.runSync (
463
+ < String > ['git' , 'tag' , '--contains' , 'HEAD' ],
464
+ workingDirectory: anyNamed ('workingDirectory' ),
465
+ environment: anyNamed ('environment' ),
466
+ )).thenReturn (RunResult (
467
+ ProcessResult (1 , 0 , '1.2.3-0.0.pre\n 1.2.3\n 1.2.3-0.1.pre' , '' ),
468
+ < String > ['git' , 'tag' , '--contains' , 'HEAD' ],
469
+ ));
470
+ final GitTagVersion version = GitTagVersion .determine (mockProcessUtils, workingDirectory: '.' );
471
+ expect (version.gitTag, '1.2.3' );
472
+ expect (version.devPatch, null );
473
+ expect (version.devVersion, null );
474
+ // We shouldn't have to fallback to git describe, because we are exactly
475
+ // on a release tag.
476
+ verifyNever (mockProcessUtils.runSync (
477
+ < String > ['git' , 'describe' , '--match' , '*.*.*-*.*.pre' , '--first-parent' , '--long' , '--tags' ],
478
+ workingDirectory: anyNamed ('workingDirectory' ),
479
+ environment: anyNamed ('environment' ),
480
+ ));
481
+ });
482
+
451
483
testUsingContext ('determine does not call fetch --tags' , () {
452
484
final MockProcessUtils processUtils = MockProcessUtils ();
453
485
when (processUtils.runSync (
@@ -456,10 +488,18 @@ void main() {
456
488
environment: anyNamed ('environment' ),
457
489
)).thenReturn (RunResult (ProcessResult (105 , 0 , '' , '' ), < String > ['git' , 'fetch' ]));
458
490
when (processUtils.runSync (
459
- < String > ['git' , 'describe' , '--match' , '*.*.*' , '--first-parent' , '--long' , '--tags' ],
491
+ < String > ['git' , 'describe' , '--match' , '*.*.*-*.*.pre ' , '--first-parent' , '--long' , '--tags' ],
460
492
workingDirectory: anyNamed ('workingDirectory' ),
461
493
environment: anyNamed ('environment' ),
462
494
)).thenReturn (RunResult (ProcessResult (106 , 0 , 'v0.1.2-3-1234abcd' , '' ), < String > ['git' , 'describe' ]));
495
+ when (processUtils.runSync (
496
+ < String > ['git' , 'tag' , '--contains' , 'HEAD' ],
497
+ workingDirectory: anyNamed ('workingDirectory' ),
498
+ environment: anyNamed ('environment' ),
499
+ )).thenReturn (
500
+ RunResult (ProcessResult (110 , 0 , '' , '' ),
501
+ < String > ['git' , 'tag' , '--contains' , 'HEAD' ],
502
+ ));
463
503
464
504
GitTagVersion .determine (processUtils, workingDirectory: '.' );
465
505
@@ -474,7 +514,7 @@ void main() {
474
514
environment: anyNamed ('environment' ),
475
515
));
476
516
verify (processUtils.runSync (
477
- < String > ['git' , 'describe' , '--match' , '*.*.*' , '--first-parent' , '--long' , '--tags' ],
517
+ < String > ['git' , 'describe' , '--match' , '*.*.*-*.*.pre ' , '--first-parent' , '--long' , '--tags' ],
478
518
workingDirectory: anyNamed ('workingDirectory' ),
479
519
environment: anyNamed ('environment' ),
480
520
)).called (1 );
@@ -493,10 +533,18 @@ void main() {
493
533
environment: anyNamed ('environment' ),
494
534
)).thenReturn (RunResult (ProcessResult (106 , 0 , '' , '' ), < String > ['git' , 'fetch' ]));
495
535
when (processUtils.runSync (
496
- < String > ['git' , 'describe' , '--match' , '*.*.*' , '--first-parent' , '--long' , '--tags' ],
536
+ < String > ['git' , 'describe' , '--match' , '*.*.*-*.*.pre ' , '--first-parent' , '--long' , '--tags' ],
497
537
workingDirectory: anyNamed ('workingDirectory' ),
498
538
environment: anyNamed ('environment' ),
499
539
)).thenReturn (RunResult (ProcessResult (107 , 0 , 'v0.1.2-3-1234abcd' , '' ), < String > ['git' , 'describe' ]));
540
+ when (processUtils.runSync (
541
+ < String > ['git' , 'tag' , '--contains' , 'HEAD' ],
542
+ workingDirectory: anyNamed ('workingDirectory' ),
543
+ environment: anyNamed ('environment' ),
544
+ )).thenReturn (
545
+ RunResult (ProcessResult (108 , 0 , '' , '' ),
546
+ < String > ['git' , 'tag' , '--contains' , 'HEAD' ],
547
+ ));
500
548
501
549
GitTagVersion .determine (processUtils, workingDirectory: '.' , fetchTags: true );
502
550
@@ -511,7 +559,7 @@ void main() {
511
559
environment: anyNamed ('environment' ),
512
560
));
513
561
verify (processUtils.runSync (
514
- < String > ['git' , 'describe' , '--match' , '*.*.*' , '--first-parent' , '--long' , '--tags' ],
562
+ < String > ['git' , 'describe' , '--match' , '*.*.*-*.*.pre ' , '--first-parent' , '--long' , '--tags' ],
515
563
workingDirectory: anyNamed ('workingDirectory' ),
516
564
environment: anyNamed ('environment' ),
517
565
)).called (1 );
@@ -530,10 +578,18 @@ void main() {
530
578
environment: anyNamed ('environment' ),
531
579
)).thenReturn (RunResult (ProcessResult (109 , 0 , '' , '' ), < String > ['git' , 'fetch' ]));
532
580
when (processUtils.runSync (
533
- < String > ['git' , 'describe' , '--match' , '*.*.*' , '--first-parent' , '--long' , '--tags' ],
581
+ < String > ['git' , 'tag' , '--contains' , 'HEAD' ],
582
+ workingDirectory: anyNamed ('workingDirectory' ),
583
+ environment: anyNamed ('environment' ),
584
+ )).thenReturn (
585
+ RunResult (ProcessResult (110 , 0 , '' , '' ),
586
+ < String > ['git' , 'tag' , '--contains' , 'HEAD' ],
587
+ ));
588
+ when (processUtils.runSync (
589
+ < String > ['git' , 'describe' , '--match' , '*.*.*-*.*.pre' , '--first-parent' , '--long' , '--tags' ],
534
590
workingDirectory: anyNamed ('workingDirectory' ),
535
591
environment: anyNamed ('environment' ),
536
- )).thenReturn (RunResult (ProcessResult (110 , 0 , 'v0.1.2-3-1234abcd' , '' ), < String > ['git' , 'describe' ]));
592
+ )).thenReturn (RunResult (ProcessResult (111 , 0 , 'v0.1.2-3-1234abcd' , '' ), < String > ['git' , 'describe' ]));
537
593
538
594
GitTagVersion .determine (processUtils, workingDirectory: '.' , fetchTags: true );
539
595
@@ -548,7 +604,7 @@ void main() {
548
604
environment: anyNamed ('environment' ),
549
605
)).called (1 );
550
606
verify (processUtils.runSync (
551
- < String > ['git' , 'describe' , '--match' , '*.*.*' , '--first-parent' , '--long' , '--tags' ],
607
+ < String > ['git' , 'describe' , '--match' , '*.*.*-*.*.pre ' , '--first-parent' , '--long' , '--tags' ],
552
608
workingDirectory: anyNamed ('workingDirectory' ),
553
609
environment: anyNamed ('environment' ),
554
610
)).called (1 );
@@ -669,10 +725,15 @@ void fakeData(
669
725
environment: anyNamed ('environment' ),
670
726
)).thenReturn (ProcessResult (105 , 0 , '' , '' ));
671
727
when (pm.runSync (
672
- < String > ['git' , 'describe' , '--match' , '*.*.*' , '--first-parent' , '--long' , '--tags' ],
728
+ < String > ['git' , 'tag' , '--contains' , 'HEAD' ],
729
+ workingDirectory: anyNamed ('workingDirectory' ),
730
+ environment: anyNamed ('environment' ),
731
+ )).thenReturn (ProcessResult (106 , 0 , '' , '' ));
732
+ when (pm.runSync (
733
+ < String > ['git' , 'describe' , '--match' , '*.*.*-*.*.pre' , '--first-parent' , '--long' , '--tags' ],
673
734
workingDirectory: anyNamed ('workingDirectory' ),
674
735
environment: anyNamed ('environment' ),
675
- )).thenReturn (ProcessResult (106 , 0 , 'v0.1.2-3-1234abcd' , '' ));
736
+ )).thenReturn (ProcessResult (107 , 0 , 'v0.1.2-3-1234abcd' , '' ));
676
737
}
677
738
678
739
class MockProcessManager extends Mock implements ProcessManager {}
0 commit comments