diff --git a/packages/flutter_tools/lib/src/commands/upgrade.dart b/packages/flutter_tools/lib/src/commands/upgrade.dart index b7b54a190a..d9918e385e 100644 --- a/packages/flutter_tools/lib/src/commands/upgrade.dart +++ b/packages/flutter_tools/lib/src/commands/upgrade.dart @@ -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), diff --git a/packages/flutter_tools/test/commands.shard/hermetic/upgrade_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/upgrade_test.dart index 2a1db24d57..3b7c116fc6 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/upgrade_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/upgrade_test.dart @@ -23,9 +23,11 @@ void main() { late FakeProcessManager processManager; UpgradeCommand command; late CommandRunner runner; + const String flutterRoot = '/path/to/flutter'; setUpAll(() { Cache.disableLocking(); + Cache.flutterRoot = flutterRoot; }); setUp(() { @@ -214,28 +216,35 @@ void main() { const FakeCommand( command: ['git', 'tag', '--points-at', 'HEAD'], stdout: startingTag, + workingDirectory: flutterRoot, ), const FakeCommand( command: ['git', 'fetch', '--tags'], + workingDirectory: flutterRoot, ), const FakeCommand( command: ['git', 'rev-parse', '--verify', '@{upstream}'], stdout: upstreamHeadRevision, + workingDirectory: flutterRoot, ), const FakeCommand( command: ['git', 'tag', '--points-at', upstreamHeadRevision], stdout: latestUpstreamTag, + workingDirectory: flutterRoot, ), const FakeCommand( command: ['git', 'status', '-s'], + workingDirectory: flutterRoot, ), const FakeCommand( command: ['git', 'reset', '--hard', upstreamHeadRevision], + workingDirectory: flutterRoot, ), FakeCommand( command: const ['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: ['git', 'tag', '--points-at', 'HEAD'], stdout: latestUpstreamTag, + workingDirectory: flutterRoot, ), const FakeCommand( command: ['bin/flutter', '--no-color', '--no-version-check', 'precache'], + workingDirectory: flutterRoot, ), const FakeCommand( command: ['bin/flutter', '--no-version-check', 'doctor'], + workingDirectory: flutterRoot, ), ]); await runner.run(['upgrade']); diff --git a/packages/flutter_tools/test/integration.shard/downgrade_upgrade_integration_test.dart b/packages/flutter_tools/test/integration.shard/downgrade_upgrade_integration_test.dart index 8ca82c0d25..20b7675b78 100644 --- a/packages/flutter_tools/test/integration.shard/downgrade_upgrade_integration_test.dart +++ b/packages/flutter_tools/test/integration.shard/downgrade_upgrade_integration_test.dart @@ -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([ '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([ @@ -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([ @@ -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([ @@ -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([