Unverified Commit 9a0d4cf7 authored by xster's avatar xster Committed by GitHub

Add a Flutter version comparison function (#12959)

* add git version comparison function

* use [] in dartdoc

* Make method instance method
parent 473d75a6
......@@ -167,6 +167,20 @@ class FlutterVersion {
return _branch;
}
/// Returns true if `tentativeDescendantRevision` is a direct descendant to
/// the `tentativeAncestorRevision` revision on the Flutter framework repo
/// tree.
bool checkRevisionAncestry({
String tentativeDescendantRevision,
String tentativeAncestorRevision,
}) {
final ProcessResult result = processManager.runSync(
<String>['git', 'merge-base', '--is-ancestor', tentativeAncestorRevision, tentativeDescendantRevision],
workingDirectory: Cache.flutterRoot,
);
return result.exitCode == 0;
}
/// The amount of time we wait before pinging the server to check for the
/// availability of a newer version of Flutter.
@visibleForTesting
......
......@@ -26,11 +26,17 @@ final DateTime _stampOutOfDate = _testClock.agoBy(FlutterVersion.kCheckAgeConsid
void main() {
group('$FlutterVersion', () {
ProcessManager mockProcessManager;
setUpAll(() {
Cache.disableLocking();
FlutterVersion.kPauseToLetUserReadTheMessage = Duration.ZERO;
});
setUp(() {
mockProcessManager = new MockProcessManager();
});
testFlutterVersion('prints nothing when Flutter installation looks fresh', () async {
fakeData(localCommitDate: _upToDateVersion);
await FlutterVersion.instance.checkFlutterVersionFreshness();
......@@ -143,6 +149,30 @@ void main() {
await version.checkFlutterVersionFreshness();
_expectVersionMessage('');
});
testUsingContext('versions comparison', () async {
when(mockProcessManager.runSync(
<String>['git', 'merge-base', '--is-ancestor', 'abcdef', '123456'],
workingDirectory: any,
)).thenReturn(new ProcessResult(1, 0, '', ''));
expect(
FlutterVersion.instance.checkRevisionAncestry(
tentativeDescendantRevision: '123456',
tentativeAncestorRevision: 'abcdef',
),
true
);
verify(mockProcessManager.runSync(
<String>['git', 'merge-base', '--is-ancestor', 'abcdef', '123456'],
workingDirectory: any,
));
},
overrides: <Type, Generator>{
FlutterVersion: () => new FlutterVersion(_testClock),
ProcessManager: () => mockProcessManager,
});
});
group('$VersionCheckStamp', () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment