Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flutter_tools] Fix "FormatException: Invalid date format" during version freshness check #134088

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/flutter_tools/lib/src/version.dart
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ abstract class FlutterVersion {
localFrameworkCommitDate = DateTime.parse(_gitCommitDate(workingDirectory: flutterRoot));
} on VersionCheckError {
return;
} on FormatException {
return;
}
final DateTime? latestFlutterCommitDate = await _getLatestAvailableFlutterDate();

Expand Down
44 changes: 44 additions & 0 deletions packages/flutter_tools/test/general.shard/version_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,50 @@ void main() {
Cache: () => cache,
});

testUsingContext('does not crash when git log outputs malformed output', () async {
const String flutterUpstreamUrl = 'https://github.com/flutter/flutter.git';

final String malformedGitLogOutput = '${getChannelUpToDateVersion()}[0x7FF9E2A75000] ANOMALY: meaningless REX prefix used';
processManager.addCommands(<FakeCommand>[
const FakeCommand(
command: <String>['git', '-c', 'log.showSignature=false', 'log', '-n', '1', '--pretty=format:%H'],
stdout: '1234abcd',
),
const FakeCommand(
command: <String>['git', 'tag', '--points-at', '1234abcd'],
),
const FakeCommand(
command: <String>['git', 'describe', '--match', '*.*.*', '--long', '--tags', '1234abcd'],
stdout: '0.1.2-3-1234abcd',
),
FakeCommand(
command: const <String>['git', 'symbolic-ref', '--short', 'HEAD'],
stdout: channel,
),
FakeCommand(
command: const <String>['git', 'rev-parse', '--abbrev-ref', '--symbolic', '@{upstream}'],
stdout: 'origin/$channel',
),
const FakeCommand(
command: <String>['git', 'ls-remote', '--get-url', 'origin'],
stdout: flutterUpstreamUrl,
),
FakeCommand(
command: const <String>['git', '-c', 'log.showSignature=false', 'log', 'HEAD', '-n', '1', '--pretty=format:%ad', '--date=iso'],
stdout: malformedGitLogOutput,
),
]);

final FlutterVersion flutterVersion = FlutterVersion(clock: _testClock, fs: fs, flutterRoot: flutterRoot);
await flutterVersion.checkFlutterVersionFreshness();

expect(testLogger.statusText, isEmpty);
expect(processManager, hasNoRemainingExpectations);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
Cache: () => cache,
});

testWithoutContext('prints nothing when Flutter installation looks out-of-date but is actually up-to-date', () async {
final FakeFlutterVersion flutterVersion = FakeFlutterVersion(branch: channel);
final BufferLogger logger = BufferLogger.test();
Expand Down