Unverified Commit 33210218 authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

[flutter_tools] Fix flutter upgrade not finding git tags (#133778)

Fixes https://github.com/flutter/flutter/issues/133441
parent 0b3b8cd5
......@@ -77,7 +77,11 @@ class UpgradeCommand extends FlutterCommand {
force: boolArg('force'),
continueFlow: boolArg('continue'),
testFlow: stringArg('working-directory') != null,
gitTagVersion: GitTagVersion.determine(globals.processUtils, globals.platform),
gitTagVersion: GitTagVersion.determine(
globals.processUtils,
globals.platform,
workingDirectory: _commandRunner.workingDirectory,
),
flutterVersion: stringArg('working-directory') == null
? globals.flutterVersion
: FlutterVersion(flutterRoot: _commandRunner.workingDirectory!, fs: globals.fs),
......
......@@ -23,9 +23,11 @@ void main() {
late FakeProcessManager processManager;
UpgradeCommand command;
late CommandRunner<void> runner;
const String flutterRoot = '/path/to/flutter';
setUpAll(() {
Cache.disableLocking();
Cache.flutterRoot = flutterRoot;
});
setUp(() {
......@@ -214,28 +216,35 @@ void main() {
const FakeCommand(
command: <String>['git', 'tag', '--points-at', 'HEAD'],
stdout: startingTag,
workingDirectory: flutterRoot,
),
const FakeCommand(
command: <String>['git', 'fetch', '--tags'],
workingDirectory: flutterRoot,
),
const FakeCommand(
command: <String>['git', 'rev-parse', '--verify', '@{upstream}'],
stdout: upstreamHeadRevision,
workingDirectory: flutterRoot,
),
const FakeCommand(
command: <String>['git', 'tag', '--points-at', upstreamHeadRevision],
stdout: latestUpstreamTag,
workingDirectory: flutterRoot,
),
const FakeCommand(
command: <String>['git', 'status', '-s'],
workingDirectory: flutterRoot,
),
const FakeCommand(
command: <String>['git', 'reset', '--hard', upstreamHeadRevision],
workingDirectory: flutterRoot,
),
FakeCommand(
command: const <String>['bin/flutter', 'upgrade', '--continue', '--no-version-check'],
onRun: reEnterTool,
completer: reEntryCompleter,
workingDirectory: flutterRoot,
),
// commands following this are from the re-entrant `flutter upgrade --continue` call
......@@ -243,12 +252,15 @@ void main() {
const FakeCommand(
command: <String>['git', 'tag', '--points-at', 'HEAD'],
stdout: latestUpstreamTag,
workingDirectory: flutterRoot,
),
const FakeCommand(
command: <String>['bin/flutter', '--no-color', '--no-version-check', 'precache'],
workingDirectory: flutterRoot,
),
const FakeCommand(
command: <String>['bin/flutter', '--no-version-check', 'doctor'],
workingDirectory: flutterRoot,
),
]);
await runner.run(<String>['upgrade']);
......
......@@ -15,14 +15,14 @@ const String _kInitialVersion = '3.0.0';
const String _kBranch = 'beta';
final Stdio stdio = Stdio();
final ProcessUtils processUtils = ProcessUtils(processManager: processManager, logger: StdoutLogger(
final BufferLogger logger = BufferLogger.test(
terminal: AnsiTerminal(
platform: platform,
stdio: stdio,
),
stdio: stdio,
outputPreferences: OutputPreferences.test(wrapText: true),
));
);
final ProcessUtils processUtils = ProcessUtils(processManager: processManager, logger: logger);
final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', platform.isWindows ? 'flutter.bat' : 'flutter');
/// A test for flutter upgrade & downgrade that checks out a parallel flutter repo.
......@@ -48,13 +48,29 @@ void main() {
'git', 'config', '--system', 'core.longpaths', 'true',
]);
void checkExitCode(int code) {
expect(
exitCode,
0,
reason: '''
trace:
${logger.traceText}
status:
${logger.statusText}
error:
${logger.errorText}''',
);
}
printOnFailure('Step 1 - clone the $_kBranch of flutter into the test directory');
exitCode = await processUtils.stream(<String>[
'git',
'clone',
'https://github.com/flutter/flutter.git',
], workingDirectory: parentDirectory.path, trace: true);
expect(exitCode, 0);
checkExitCode(exitCode);
printOnFailure('Step 2 - switch to the $_kBranch');
exitCode = await processUtils.stream(<String>[
......@@ -65,7 +81,7 @@ void main() {
_kBranch,
'origin/$_kBranch',
], workingDirectory: testDirectory.path, trace: true);
expect(exitCode, 0);
checkExitCode(exitCode);
printOnFailure('Step 3 - revert back to $_kInitialVersion');
exitCode = await processUtils.stream(<String>[
......@@ -74,7 +90,7 @@ void main() {
'--hard',
_kInitialVersion,
], workingDirectory: testDirectory.path, trace: true);
expect(exitCode, 0);
checkExitCode(exitCode);
printOnFailure('Step 4 - upgrade to the newest $_kBranch');
// This should update the persistent tool state with the sha for HEAD
......@@ -84,8 +100,10 @@ void main() {
'upgrade',
'--verbose',
'--working-directory=${testDirectory.path}',
], workingDirectory: testDirectory.path, trace: true);
expect(exitCode, 0);
// we intentionally run this in a directory outside the test repo to
// verify the tool overrides the working directory when invoking git
], workingDirectory: parentDirectory.path, trace: true);
checkExitCode(exitCode);
printOnFailure('Step 5 - verify that the version is different');
final RunResult versionResult = await processUtils.run(<String>[
......@@ -105,8 +123,8 @@ void main() {
'downgrade',
'--no-prompt',
'--working-directory=${testDirectory.path}',
], workingDirectory: testDirectory.path, trace: true);
expect(exitCode, 0);
], workingDirectory: parentDirectory.path, trace: true);
checkExitCode(exitCode);
printOnFailure('Step 7 - verify downgraded version matches original version');
final RunResult oldVersionResult = await processUtils.run(<String>[
......
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