diff --git a/packages/shorebird_cli/lib/src/shorebird_env.dart b/packages/shorebird_cli/lib/src/shorebird_env.dart index 5c7d2859..709f38c9 100644 --- a/packages/shorebird_cli/lib/src/shorebird_env.dart +++ b/packages/shorebird_cli/lib/src/shorebird_env.dart @@ -43,6 +43,17 @@ class ShorebirdEnv { ).readAsStringSync().trim(); } + set flutterRevision(String revision) { + if (revision == flutterRevision) return; + File( + p.join(shorebirdRoot.path, 'bin', 'internal', 'flutter.version'), + ).writeAsStringSync(revision); + final snapshot = File( + p.join(shorebirdRoot.path, 'bin', 'cache', 'shorebird.snapshot'), + ); + if (snapshot.existsSync()) snapshot.deleteSync(); + } + String get flutterRevision { return _flutterRevisionOverride ?? File( diff --git a/packages/shorebird_cli/test/src/shorebird_env_test.dart b/packages/shorebird_cli/test/src/shorebird_env_test.dart index 9f88f26d..ed9e4182 100644 --- a/packages/shorebird_cli/test/src/shorebird_env_test.dart +++ b/packages/shorebird_cli/test/src/shorebird_env_test.dart @@ -384,6 +384,66 @@ test-revision equals(override), ); }); + + test('can be set', () { + const newRevision = 'new-revision'; + const revision = ''' + +test-revision + +\r\n +'''; + final version = File( + p.join(shorebirdRoot.path, 'bin', 'internal', 'flutter.version'), + ) + ..createSync(recursive: true) + ..writeAsStringSync(revision, flush: true); + final snapshot = File( + p.join(shorebirdRoot.path, 'bin', 'cache', 'shorebird.snapshot')) + ..createSync(recursive: true); + + expect( + runWithOverrides(() => shorebirdEnv.flutterRevision), + 'test-revision', + ); + runWithOverrides(() => shorebirdEnv.flutterRevision = newRevision); + expect(snapshot.existsSync(), isFalse); + expect(version.readAsStringSync(), equals(newRevision)); + expect( + runWithOverrides(() => shorebirdEnv.flutterRevision), + newRevision, + ); + }); + + test('setting to the same value does nothing', () { + const newRevision = 'test-revision'; + const revision = ''' + +test-revision + +\r\n +'''; + final version = File( + p.join(shorebirdRoot.path, 'bin', 'internal', 'flutter.version'), + ) + ..createSync(recursive: true) + ..writeAsStringSync(revision, flush: true); + final snapshot = File( + p.join(shorebirdRoot.path, 'bin', 'cache', 'shorebird.snapshot')) + ..createSync(recursive: true); + + expect( + runWithOverrides(() => shorebirdEnv.flutterRevision), + 'test-revision', + ); + runWithOverrides(() => shorebirdEnv.flutterRevision = newRevision); + expect(snapshot.existsSync(), isTrue); + expect(version.readAsStringSync(), equals(revision)); + expect( + runWithOverrides(() => shorebirdEnv.flutterRevision), + newRevision, + ); + }); }); group('shorebirdEngineRevision', () {