[flutter_tools] Fix flutter upgrade not finding git tags (#133778)
Fixes https://github.com/flutter/flutter/issues/133441
This commit is contained in:
parent
0b3b8cd551
commit
33210218ba
@ -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>[
|
||||
|
Loading…
x
Reference in New Issue
Block a user