Skip to content

Commit de6c00b

Browse files
authored
[flutter_tools] forward --offline flag to pub.get in update-packages (flutter#193619)
When running `flutter update-packages --offline`, the `--offline` flag was parsed and used to validate incompatible option combinations (such as `--force-upgrade` and `--cherry-pick-package`), but was not forwarded to the underlying `pub.get` invocations. Forward `offline` through `_pubGet` to `pub.get` so that `pub` does not attempt network operations in offline environments. Fixes flutter#193423 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing.
1 parent 3280748 commit de6c00b

2 files changed

Lines changed: 61 additions & 5 deletions

File tree

‎packages/flutter_tools/lib/src/commands/update_packages.dart‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,20 +243,36 @@ class UpdatePackagesCommand extends FlutterCommand {
243243
_checkPins(rootDirectory);
244244

245245
// Pub get for the workspace.
246-
await _pubGet(rootProject, !forceUpgrade && cherryPicks.isEmpty && !updateHashes);
246+
await _pubGet(
247+
rootProject,
248+
enforceLockfile: !forceUpgrade && cherryPicks.isEmpty && !updateHashes,
249+
offline: offline,
250+
);
247251

248252
// Manually do a pub get for packages not part of the workspace.
249253
// See https://github.com/flutter/flutter/pull/170364.
250-
await _pubGet(toolProject, false);
251-
await _pubGet(FlutterProject.fromDirectory(hooksUserDefineIntegrationTestDirectory), false);
254+
await _pubGet(toolProject, enforceLockfile: false, offline: offline);
255+
await _pubGet(
256+
FlutterProject.fromDirectory(hooksUserDefineIntegrationTestDirectory),
257+
enforceLockfile: false,
258+
offline: offline,
259+
);
252260

253261
await _downloadCoverageData();
254262

255263
return FlutterCommandResult.success();
256264
}
257265

258-
Future<void> _pubGet(FlutterProject project, bool enforceLockfile) async =>
259-
pub.get(context: PubContext.pubGet, project: project, enforceLockfile: enforceLockfile);
266+
Future<void> _pubGet(
267+
FlutterProject project, {
268+
required bool enforceLockfile,
269+
required bool offline,
270+
}) async => pub.get(
271+
context: PubContext.pubGet,
272+
project: project,
273+
enforceLockfile: enforceLockfile,
274+
offline: offline,
275+
);
260276

261277
Future<List<_ProjectDeps>> _upgrade({
262278
required bool forceUpgrade,

‎packages/flutter_tools/test/commands.shard/hermetic/update_packages_test.dart‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,37 @@ void main() {
294294
pub.pubspecs[flutterSdk.absolute.path]!.first.dependencies,
295295
Pubspec.parse(kFlutterWorkspacePubspecYaml).dependencies,
296296
);
297+
expect(pub.recordedPubGets, hasLength(3));
298+
expect(pub.recordedPubGets.map((r) => r.offline), everyElement(isFalse));
299+
expect(pub.recordedPubGets[0].enforceLockfile, isTrue);
300+
expect(pub.recordedPubGets[1].enforceLockfile, isFalse);
301+
expect(pub.recordedPubGets[2].enforceLockfile, isFalse);
302+
},
303+
overrides: <Type, Generator>{
304+
Pub: () => pub,
305+
FileSystem: () => fileSystem,
306+
ProcessManager: () => processManager,
307+
Cache: () => Cache.test(processManager: processManager),
308+
},
309+
);
310+
311+
testUsingContext(
312+
'updates packages --offline passes offline flag to pub get',
313+
() async {
314+
final command = UpdatePackagesCommand(
315+
toolContext: DelegatingToolContext(),
316+
verboseHelp: false,
317+
);
318+
await createTestCommandRunner(command).run(<String>['update-packages', '--offline']);
319+
expect(
320+
pub.pubspecs[flutterSdk.absolute.path]!.first.dependencies,
321+
Pubspec.parse(kFlutterWorkspacePubspecYaml).dependencies,
322+
);
323+
expect(pub.recordedPubGets, hasLength(3));
324+
expect(pub.recordedPubGets.map((r) => r.offline), everyElement(isTrue));
325+
expect(pub.recordedPubGets[0].enforceLockfile, isTrue);
326+
expect(pub.recordedPubGets[1].enforceLockfile, isFalse);
327+
expect(pub.recordedPubGets[2].enforceLockfile, isFalse);
297328
},
298329
overrides: <Type, Generator>{
299330
Pub: () => pub,
@@ -637,6 +668,9 @@ class _FakePub extends Fake implements Pub {
637668
(pubspecs[project.directory.path] ??= <Pubspec>[]).add(pubspec);
638669
}
639670

671+
final recordedPubGets =
672+
<({PubContext context, FlutterProject project, bool enforceLockfile, bool offline})>[];
673+
640674
@override
641675
Future<void> get({
642676
required PubContext context,
@@ -649,6 +683,12 @@ class _FakePub extends Fake implements Pub {
649683
bool enforceLockfile = false,
650684
PubOutputMode outputMode = PubOutputMode.all,
651685
}) async {
686+
recordedPubGets.add((
687+
context: context,
688+
project: project,
689+
enforceLockfile: enforceLockfile,
690+
offline: offline,
691+
));
652692
(pubspecs[project.directory.path] ??= <Pubspec>[]).add(
653693
Pubspec.parse(project.pubspecFile.readAsStringSync()),
654694
);

0 commit comments

Comments
 (0)