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