Unverified Commit 20bf43b9 authored by Dan Field's avatar Dan Field Committed by GitHub

Fix version command for certain git workflows (#52062)

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