Commit 4277f364 authored by ∂ω∂'s avatar ∂ω∂ Committed by Jenn Magder

flutter_tools/version: git log.showSignature=false (#38576)

parent 6a5d3296
...@@ -662,7 +662,7 @@ int _getPrNumber() { ...@@ -662,7 +662,7 @@ int _getPrNumber() {
Future<String> _getAuthors() async { Future<String> _getAuthors() async {
final String exe = Platform.isWindows ? '.exe' : ''; final String exe = Platform.isWindows ? '.exe' : '';
final String author = await runAndGetStdout( final String author = await runAndGetStdout(
'git$exe', <String>['log', _getGitHash(), '--pretty="%an <%ae>"'], 'git$exe', <String>['-c', 'log.showSignature=false', 'log', _getGitHash(), '--pretty="%an <%ae>"'],
workingDirectory: flutterRoot, workingDirectory: flutterRoot,
).first; ).first;
return author; return author;
......
...@@ -20,7 +20,7 @@ import 'globals.dart'; ...@@ -20,7 +20,7 @@ import 'globals.dart';
class FlutterVersion { class FlutterVersion {
@visibleForTesting @visibleForTesting
FlutterVersion([this._clock = const SystemClock()]) { FlutterVersion([this._clock = const SystemClock()]) {
_frameworkRevision = _runGit('git log -n 1 --pretty=format:%H'); _frameworkRevision = _runGit(gitLog(<String>['-n', '1', '--pretty=format:%H']).join(' '));
_frameworkVersion = GitTagVersion.determine().frameworkVersionFor(_frameworkRevision); _frameworkVersion = GitTagVersion.determine().frameworkVersionFor(_frameworkRevision);
} }
...@@ -86,7 +86,7 @@ class FlutterVersion { ...@@ -86,7 +86,7 @@ class FlutterVersion {
String _frameworkAge; String _frameworkAge;
String get frameworkAge { String get frameworkAge {
return _frameworkAge ??= _runGit('git log -n 1 --pretty=format:%ar'); return _frameworkAge ??= _runGit(gitLog(<String>['-n', '1', '--pretty=format:%ar']).join(' '));
} }
String _frameworkVersion; String _frameworkVersion;
...@@ -134,15 +134,13 @@ class FlutterVersion { ...@@ -134,15 +134,13 @@ class FlutterVersion {
String get frameworkCommitDate => _latestGitCommitDate(); String get frameworkCommitDate => _latestGitCommitDate();
static String _latestGitCommitDate([ String branch ]) { static String _latestGitCommitDate([ String branch ]) {
final List<String> args = <String>[ final List<String> args = gitLog(<String>[
'git',
'log',
if (branch != null) branch, if (branch != null) branch,
'-n', '-n',
'1', '1',
'--pretty=format:%ad', '--pretty=format:%ad',
'--date=iso', '--date=iso',
]; ]);
return _runSync(args, lenient: false); return _runSync(args, lenient: false);
} }
...@@ -332,6 +330,14 @@ class FlutterVersion { ...@@ -332,6 +330,14 @@ class FlutterVersion {
} }
} }
/// log.showSignature=false is a user setting and it will break things,
/// so we want to disable it for every git log call. This is a convenience
/// wrapper that does that.
@visibleForTesting
static List<String> gitLog(List<String> args) {
return <String>['git', '-c', 'log.showSignature=false', 'log'] + args;
}
@visibleForTesting @visibleForTesting
static String versionOutOfDateMessage(Duration frameworkAge) { static String versionOutOfDateMessage(Duration frameworkAge) {
String warning = 'WARNING: your installation of Flutter is ${frameworkAge.inDays} days old.'; String warning = 'WARNING: your installation of Flutter is ${frameworkAge.inDays} days old.';
......
...@@ -10,6 +10,7 @@ import 'package:flutter_tools/src/base/common.dart'; ...@@ -10,6 +10,7 @@ import 'package:flutter_tools/src/base/common.dart';
import 'package:flutter_tools/src/base/io.dart'; import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/version.dart'; import 'package:flutter_tools/src/commands/version.dart';
import 'package:flutter_tools/src/version.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
import 'package:process/process.dart'; import 'package:process/process.dart';
...@@ -116,7 +117,7 @@ class MockProcessManager extends Mock implements ProcessManager { ...@@ -116,7 +117,7 @@ class MockProcessManager extends Mock implements ProcessManager {
Encoding stderrEncoding = systemEncoding, Encoding stderrEncoding = systemEncoding,
}) { }) {
final String commandStr = command.join(' '); final String commandStr = command.join(' ');
if (commandStr == 'git log -n 1 --pretty=format:%H') { if (commandStr == FlutterVersion.gitLog(<String>['-n', '1', '--pretty=format:%H']).join(' ')) {
return ProcessResult(0, 0, '000000000000000000000', ''); return ProcessResult(0, 0, '000000000000000000000', '');
} }
if (commandStr == if (commandStr ==
......
...@@ -132,7 +132,7 @@ void main() { ...@@ -132,7 +132,7 @@ void main() {
testUsingContext('checks that Flutter toJson output reports the flutter framework version', () async { testUsingContext('checks that Flutter toJson output reports the flutter framework version', () async {
final ProcessResult result = ProcessResult(0, 0, 'random', '0'); final ProcessResult result = ProcessResult(0, 0, 'random', '0');
when(processManager.runSync('git log -n 1 --pretty=format:%H'.split(' '), when(processManager.runSync(FlutterVersion.gitLog('-n 1 --pretty=format:%H'.split(' ')),
workingDirectory: Cache.flutterRoot)).thenReturn(result); workingDirectory: Cache.flutterRoot)).thenReturn(result);
when(processManager.runSync('git rev-parse --abbrev-ref --symbolic @{u}'.split(' '), when(processManager.runSync('git rev-parse --abbrev-ref --symbolic @{u}'.split(' '),
workingDirectory: Cache.flutterRoot)).thenReturn(result); workingDirectory: Cache.flutterRoot)).thenReturn(result);
...@@ -140,11 +140,11 @@ void main() { ...@@ -140,11 +140,11 @@ void main() {
workingDirectory: Cache.flutterRoot)).thenReturn(result); workingDirectory: Cache.flutterRoot)).thenReturn(result);
when(processManager.runSync('git ls-remote --get-url master'.split(' '), when(processManager.runSync('git ls-remote --get-url master'.split(' '),
workingDirectory: Cache.flutterRoot)).thenReturn(result); workingDirectory: Cache.flutterRoot)).thenReturn(result);
when(processManager.runSync('git log -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 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('git log -n 1 --pretty=format:%ad --date=iso'.split(' '), when(processManager.runSync(FlutterVersion.gitLog('-n 1 --pretty=format:%ad --date=iso'.split(' ')),
workingDirectory: Cache.flutterRoot)).thenReturn(result); workingDirectory: Cache.flutterRoot)).thenReturn(result);
final FakeFlutterVersion version = FakeFlutterVersion(); final FakeFlutterVersion version = FakeFlutterVersion();
......
...@@ -465,14 +465,18 @@ void fakeData( ...@@ -465,14 +465,18 @@ void fakeData(
}); });
final Answering<ProcessResult> syncAnswer = (Invocation invocation) { final Answering<ProcessResult> syncAnswer = (Invocation invocation) {
bool argsAre(String a1, [ String a2, String a3, String a4, String a5, String a6, String a7, String a8 ]) { bool argsAre(String a1, [ String a2, String a3, String a4, String a5, String a6, String a7, String a8, String a9 ]) {
const ListEquality<String> equality = ListEquality<String>(); const ListEquality<String> equality = ListEquality<String>();
final List<String> args = invocation.positionalArguments.single; final List<String> args = invocation.positionalArguments.single;
final List<String> expectedArgs = <String>[a1, a2, a3, a4, a5, a6, a7, a8].where((String arg) => arg != null).toList(); final List<String> expectedArgs = <String>[a1, a2, a3, a4, a5, a6, a7, a8, a9].where((String arg) => arg != null).toList();
return equality.equals(args, expectedArgs); return equality.equals(args, expectedArgs);
} }
if (argsAre('git', 'log', '-n', '1', '--pretty=format:%ad', '--date=iso')) { bool listArgsAre(List<String> a) {
return Function.apply(argsAre, a);
}
if (listArgsAre(FlutterVersion.gitLog(<String>['-n', '1', '--pretty=format:%ad', '--date=iso']))) {
return success(localCommitDate.toString()); return success(localCommitDate.toString());
} else if (argsAre('git', 'remote')) { } else if (argsAre('git', 'remote')) {
return success(''); return success('');
...@@ -483,7 +487,8 @@ void fakeData( ...@@ -483,7 +487,8 @@ void fakeData(
fail('Did not expect server ping'); fail('Did not expect server ping');
} }
return errorOnFetch ? failure(128) : success(''); return errorOnFetch ? failure(128) : success('');
} else if (remoteCommitDate != null && argsAre('git', 'log', '__flutter_version_check__/$channel', '-n', '1', '--pretty=format:%ad', '--date=iso')) { // 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()); return success(remoteCommitDate.toString());
} }
...@@ -506,12 +511,12 @@ void fakeData( ...@@ -506,12 +511,12 @@ void fakeData(
environment: anyNamed('environment'), environment: anyNamed('environment'),
)).thenReturn(ProcessResult(102, 0, 'branch', '')); )).thenReturn(ProcessResult(102, 0, 'branch', ''));
when(pm.runSync( when(pm.runSync(
<String>['git', 'log', '-n', '1', '--pretty=format:%H'], FlutterVersion.gitLog(<String>['-n', '1', '--pretty=format:%H']),
workingDirectory: anyNamed('workingDirectory'), workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'), environment: anyNamed('environment'),
)).thenReturn(ProcessResult(103, 0, '1234abcd', '')); )).thenReturn(ProcessResult(103, 0, '1234abcd', ''));
when(pm.runSync( when(pm.runSync(
<String>['git', 'log', '-n', '1', '--pretty=format:%ar'], FlutterVersion.gitLog(<String>['-n', '1', '--pretty=format:%ar']),
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', ''));
......
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