Skip to content

Commit 3321021

Browse files
[flutter_tools] Fix flutter upgrade not finding git tags (#133778)
Fixes flutter/flutter#133441
1 parent 0b3b8cd commit 3321021

File tree

3 files changed

+45
-11
lines changed

3 files changed

+45
-11
lines changed

packages/flutter_tools/lib/src/commands/upgrade.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ class UpgradeCommand extends FlutterCommand {
7777
force: boolArg('force'),
7878
continueFlow: boolArg('continue'),
7979
testFlow: stringArg('working-directory') != null,
80-
gitTagVersion: GitTagVersion.determine(globals.processUtils, globals.platform),
80+
gitTagVersion: GitTagVersion.determine(
81+
globals.processUtils,
82+
globals.platform,
83+
workingDirectory: _commandRunner.workingDirectory,
84+
),
8185
flutterVersion: stringArg('working-directory') == null
8286
? globals.flutterVersion
8387
: FlutterVersion(flutterRoot: _commandRunner.workingDirectory!, fs: globals.fs),

packages/flutter_tools/test/commands.shard/hermetic/upgrade_test.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ void main() {
2323
late FakeProcessManager processManager;
2424
UpgradeCommand command;
2525
late CommandRunner<void> runner;
26+
const String flutterRoot = '/path/to/flutter';
2627

2728
setUpAll(() {
2829
Cache.disableLocking();
30+
Cache.flutterRoot = flutterRoot;
2931
});
3032

3133
setUp(() {
@@ -214,41 +216,51 @@ void main() {
214216
const FakeCommand(
215217
command: <String>['git', 'tag', '--points-at', 'HEAD'],
216218
stdout: startingTag,
219+
workingDirectory: flutterRoot,
217220
),
218221
const FakeCommand(
219222
command: <String>['git', 'fetch', '--tags'],
223+
workingDirectory: flutterRoot,
220224
),
221225
const FakeCommand(
222226
command: <String>['git', 'rev-parse', '--verify', '@{upstream}'],
223227
stdout: upstreamHeadRevision,
228+
workingDirectory: flutterRoot,
224229
),
225230
const FakeCommand(
226231
command: <String>['git', 'tag', '--points-at', upstreamHeadRevision],
227232
stdout: latestUpstreamTag,
233+
workingDirectory: flutterRoot,
228234
),
229235
const FakeCommand(
230236
command: <String>['git', 'status', '-s'],
237+
workingDirectory: flutterRoot,
231238
),
232239
const FakeCommand(
233240
command: <String>['git', 'reset', '--hard', upstreamHeadRevision],
241+
workingDirectory: flutterRoot,
234242
),
235243
FakeCommand(
236244
command: const <String>['bin/flutter', 'upgrade', '--continue', '--no-version-check'],
237245
onRun: reEnterTool,
238246
completer: reEntryCompleter,
247+
workingDirectory: flutterRoot,
239248
),
240249

241250
// commands following this are from the re-entrant `flutter upgrade --continue` call
242251

243252
const FakeCommand(
244253
command: <String>['git', 'tag', '--points-at', 'HEAD'],
245254
stdout: latestUpstreamTag,
255+
workingDirectory: flutterRoot,
246256
),
247257
const FakeCommand(
248258
command: <String>['bin/flutter', '--no-color', '--no-version-check', 'precache'],
259+
workingDirectory: flutterRoot,
249260
),
250261
const FakeCommand(
251262
command: <String>['bin/flutter', '--no-version-check', 'doctor'],
263+
workingDirectory: flutterRoot,
252264
),
253265
]);
254266
await runner.run(<String>['upgrade']);

packages/flutter_tools/test/integration.shard/downgrade_upgrade_integration_test.dart

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ const String _kInitialVersion = '3.0.0';
1515
const String _kBranch = 'beta';
1616

1717
final Stdio stdio = Stdio();
18-
final ProcessUtils processUtils = ProcessUtils(processManager: processManager, logger: StdoutLogger(
18+
final BufferLogger logger = BufferLogger.test(
1919
terminal: AnsiTerminal(
2020
platform: platform,
2121
stdio: stdio,
2222
),
23-
stdio: stdio,
2423
outputPreferences: OutputPreferences.test(wrapText: true),
25-
));
24+
);
25+
final ProcessUtils processUtils = ProcessUtils(processManager: processManager, logger: logger);
2626
final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', platform.isWindows ? 'flutter.bat' : 'flutter');
2727

2828
/// A test for flutter upgrade & downgrade that checks out a parallel flutter repo.
@@ -48,13 +48,29 @@ void main() {
4848
'git', 'config', '--system', 'core.longpaths', 'true',
4949
]);
5050

51+
void checkExitCode(int code) {
52+
expect(
53+
exitCode,
54+
0,
55+
reason: '''
56+
trace:
57+
${logger.traceText}
58+
59+
status:
60+
${logger.statusText}
61+
62+
error:
63+
${logger.errorText}''',
64+
);
65+
}
66+
5167
printOnFailure('Step 1 - clone the $_kBranch of flutter into the test directory');
5268
exitCode = await processUtils.stream(<String>[
5369
'git',
5470
'clone',
5571
'https://github.com/flutter/flutter.git',
5672
], workingDirectory: parentDirectory.path, trace: true);
57-
expect(exitCode, 0);
73+
checkExitCode(exitCode);
5874

5975
printOnFailure('Step 2 - switch to the $_kBranch');
6076
exitCode = await processUtils.stream(<String>[
@@ -65,7 +81,7 @@ void main() {
6581
_kBranch,
6682
'origin/$_kBranch',
6783
], workingDirectory: testDirectory.path, trace: true);
68-
expect(exitCode, 0);
84+
checkExitCode(exitCode);
6985

7086
printOnFailure('Step 3 - revert back to $_kInitialVersion');
7187
exitCode = await processUtils.stream(<String>[
@@ -74,7 +90,7 @@ void main() {
7490
'--hard',
7591
_kInitialVersion,
7692
], workingDirectory: testDirectory.path, trace: true);
77-
expect(exitCode, 0);
93+
checkExitCode(exitCode);
7894

7995
printOnFailure('Step 4 - upgrade to the newest $_kBranch');
8096
// This should update the persistent tool state with the sha for HEAD
@@ -84,8 +100,10 @@ void main() {
84100
'upgrade',
85101
'--verbose',
86102
'--working-directory=${testDirectory.path}',
87-
], workingDirectory: testDirectory.path, trace: true);
88-
expect(exitCode, 0);
103+
// we intentionally run this in a directory outside the test repo to
104+
// verify the tool overrides the working directory when invoking git
105+
], workingDirectory: parentDirectory.path, trace: true);
106+
checkExitCode(exitCode);
89107

90108
printOnFailure('Step 5 - verify that the version is different');
91109
final RunResult versionResult = await processUtils.run(<String>[
@@ -105,8 +123,8 @@ void main() {
105123
'downgrade',
106124
'--no-prompt',
107125
'--working-directory=${testDirectory.path}',
108-
], workingDirectory: testDirectory.path, trace: true);
109-
expect(exitCode, 0);
126+
], workingDirectory: parentDirectory.path, trace: true);
127+
checkExitCode(exitCode);
110128

111129
printOnFailure('Step 7 - verify downgraded version matches original version');
112130
final RunResult oldVersionResult = await processUtils.run(<String>[

0 commit comments

Comments
 (0)