mirror of
https://github.com/flutter/flutter
synced 2024-10-13 19:52:53 +00:00
Fix version command for certain git workflows (#52062)
This commit is contained in:
parent
4d05ed5deb
commit
20bf43b9eb
|
@ -23,6 +23,9 @@ enum Channel {
|
|||
stable,
|
||||
}
|
||||
|
||||
/// The flutter GitHub repository.
|
||||
const String _flutterGit = 'https://github.com/flutter/flutter.git';
|
||||
|
||||
/// Retrieve a human-readable name for a given [channel].
|
||||
///
|
||||
/// Requires [FlutterVersion.officialChannels] to be correctly ordered.
|
||||
|
@ -233,7 +236,7 @@ class FlutterVersion {
|
|||
'remote',
|
||||
'add',
|
||||
_versionCheckRemote,
|
||||
'https://github.com/flutter/flutter.git',
|
||||
_flutterGit,
|
||||
]);
|
||||
await _run(<String>['git', 'fetch', _versionCheckRemote, branch]);
|
||||
return _latestGitCommitDate(
|
||||
|
@ -702,6 +705,7 @@ class GitTagVersion {
|
|||
final String hash;
|
||||
|
||||
static GitTagVersion determine(ProcessUtils processUtils, [String workingDirectory]) {
|
||||
_runGit('git fetch $_flutterGit --tags', processUtils, workingDirectory);
|
||||
return parse(_runGit('git describe --match v*.*.* --first-parent --long --tags', processUtils, workingDirectory));
|
||||
}
|
||||
|
||||
|
|
|
@ -229,6 +229,12 @@ void main() {
|
|||
setUp(() {
|
||||
Cache.disableLocking();
|
||||
fakeProcessManager = FakeProcessManager.list(<FakeCommand>[
|
||||
const FakeCommand(
|
||||
command: <String>[
|
||||
'git', 'fetch', 'https://github.com/flutter/flutter.git', '--tags',
|
||||
],
|
||||
stdout: 'From https://github.com/flutter/flutter\n * branch HEAD -> FETCH_HEAD',
|
||||
),
|
||||
const FakeCommand(
|
||||
command: <String>[
|
||||
'git', 'describe', '--match', 'v*.*.*', '--first-parent', '--long', '--tags',
|
||||
|
|
|
@ -165,6 +165,8 @@ void main() {
|
|||
workingDirectory: Cache.flutterRoot)).thenReturn(result);
|
||||
when(processManager.runSync(FlutterVersion.gitLog('-n 1 --pretty=format:%ar'.split(' ')),
|
||||
workingDirectory: Cache.flutterRoot)).thenReturn(result);
|
||||
when(processManager.runSync('git fetch https://github.com/flutter/flutter.git --tags'.split(' '),
|
||||
workingDirectory: Cache.flutterRoot)).thenReturn(result);
|
||||
when(processManager.runSync('git describe --match v*.*.* --first-parent --long --tags'.split(' '),
|
||||
workingDirectory: Cache.flutterRoot)).thenReturn(result);
|
||||
when(processManager.runSync(FlutterVersion.gitLog('-n 1 --pretty=format:%ad --date=iso'.split(' ')),
|
||||
|
|
|
@ -7,6 +7,7 @@ import 'dart:convert';
|
|||
import 'package:collection/collection.dart' show ListEquality;
|
||||
import 'package:flutter_tools/src/base/context.dart';
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
import 'package:flutter_tools/src/base/process.dart';
|
||||
import 'package:flutter_tools/src/base/time.dart';
|
||||
import 'package:flutter_tools/src/base/utils.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
|
@ -411,6 +412,33 @@ void main() {
|
|||
'Could not interpret results of "git describe": v1.2.3-4-gxabcdef\n',
|
||||
);
|
||||
});
|
||||
|
||||
testUsingContext('determine calls fetch --tags', () {
|
||||
final MockProcessUtils processUtils = MockProcessUtils();
|
||||
when(processUtils.runSync(
|
||||
<String>['git', 'fetch', 'https://github.com/flutter/flutter.git', '--tags'],
|
||||
workingDirectory: anyNamed('workingDirectory'),
|
||||
environment: anyNamed('environment'),
|
||||
)).thenReturn(RunResult(ProcessResult(105, 0, '', ''), <String>['git', 'fetch']));
|
||||
when(processUtils.runSync(
|
||||
<String>['git', 'describe', '--match', 'v*.*.*', '--first-parent', '--long', '--tags'],
|
||||
workingDirectory: anyNamed('workingDirectory'),
|
||||
environment: anyNamed('environment'),
|
||||
)).thenReturn(RunResult(ProcessResult(106, 0, 'v0.1.2-3-1234abcd', ''), <String>['git', 'describe']));
|
||||
|
||||
GitTagVersion.determine(processUtils, '.');
|
||||
|
||||
verify(processUtils.runSync(
|
||||
<String>['git', 'fetch', 'https://github.com/flutter/flutter.git', '--tags'],
|
||||
workingDirectory: anyNamed('workingDirectory'),
|
||||
environment: anyNamed('environment'),
|
||||
)).called(1);
|
||||
verify(processUtils.runSync(
|
||||
<String>['git', 'describe', '--match', 'v*.*.*', '--first-parent', '--long', '--tags'],
|
||||
workingDirectory: anyNamed('workingDirectory'),
|
||||
environment: anyNamed('environment'),
|
||||
)).called(1);
|
||||
});
|
||||
}
|
||||
|
||||
void _expectVersionMessage(String message) {
|
||||
|
@ -489,6 +517,8 @@ void fakeData(
|
|||
// Careful here! argsAre accepts 9 arguments and FlutterVersion.gitLog adds 4.
|
||||
} else if (remoteCommitDate != null && listArgsAre(FlutterVersion.gitLog(<String>['__flutter_version_check__/$channel', '-n', '1', '--pretty=format:%ad', '--date=iso']))) {
|
||||
return success(remoteCommitDate.toString());
|
||||
} else if (argsAre('git', 'fetch', 'https://github.com/flutter/flutter.git', '--tags')) {
|
||||
return success('');
|
||||
}
|
||||
|
||||
throw StateError('Unexpected call to ProcessManager.run(${invocation.positionalArguments}, ${invocation.namedArguments})');
|
||||
|
@ -519,13 +549,18 @@ void fakeData(
|
|||
workingDirectory: anyNamed('workingDirectory'),
|
||||
environment: anyNamed('environment'),
|
||||
)).thenReturn(ProcessResult(104, 0, '1 second ago', ''));
|
||||
when(pm.runSync(
|
||||
<String>['git', 'fetch', 'https://github.com/flutter/flutter', '--tags'],
|
||||
workingDirectory: anyNamed('workingDirectory'),
|
||||
environment: anyNamed('environment'),
|
||||
)).thenReturn(ProcessResult(105, 0, '', ''));
|
||||
when(pm.runSync(
|
||||
<String>['git', 'describe', '--match', 'v*.*.*', '--first-parent', '--long', '--tags'],
|
||||
workingDirectory: anyNamed('workingDirectory'),
|
||||
environment: anyNamed('environment'),
|
||||
)).thenReturn(ProcessResult(105, 0, 'v0.1.2-3-1234abcd', ''));
|
||||
)).thenReturn(ProcessResult(106, 0, 'v0.1.2-3-1234abcd', ''));
|
||||
}
|
||||
|
||||
class MockProcessManager extends Mock implements ProcessManager {}
|
||||
|
||||
class MockProcessUtils extends Mock implements ProcessUtils {}
|
||||
class MockCache extends Mock implements Cache {}
|
||||
|
|
Loading…
Reference in a new issue