[flutter_tools] remove branch migration and standardize constructor style for version interface (#70058)

diff --git a/packages/flutter_tools/lib/src/commands/channel.dart b/packages/flutter_tools/lib/src/commands/channel.dart
index 7ab0d5f..02b1487 100644
--- a/packages/flutter_tools/lib/src/commands/channel.dart
+++ b/packages/flutter_tools/lib/src/commands/channel.dart
@@ -115,10 +115,7 @@
 
   Future<void> _switchChannel(String branchName) async {
     globals.printStatus("Switching to flutter channel '$branchName'...");
-    if (kObsoleteBranches.containsKey(branchName)) {
-      final String alternative = kObsoleteBranches[branchName];
-      globals.printStatus("This channel is obsolete. Consider switching to the '$alternative' channel instead.");
-    } else if (!kOfficialChannels.contains(branchName)) {
+    if (!kOfficialChannels.contains(branchName)) {
       globals.printStatus('This is not an official channel. For a list of available channels, try "flutter channel".');
     }
     await _checkout(branchName);
@@ -126,15 +123,6 @@
     globals.printStatus("To ensure that you're on the latest build from this channel, run 'flutter upgrade'");
   }
 
-  static Future<void> upgradeChannel() async {
-    final String channel = globals.flutterVersion.channel;
-    if (kObsoleteBranches.containsKey(channel)) {
-      final String alternative = kObsoleteBranches[channel];
-      globals.printStatus("Transitioning from '$channel' to '$alternative'...");
-      return _checkout(alternative);
-    }
-  }
-
   static Future<void> _checkout(String branchName) async {
     // Get latest refs from upstream.
     int result = await globals.processUtils.stream(
diff --git a/packages/flutter_tools/lib/src/commands/downgrade.dart b/packages/flutter_tools/lib/src/commands/downgrade.dart
index 543dafd..ddf98c2 100644
--- a/packages/flutter_tools/lib/src/commands/downgrade.dart
+++ b/packages/flutter_tools/lib/src/commands/downgrade.dart
@@ -10,7 +10,6 @@
 import '../base/logger.dart';
 import '../base/process.dart';
 import '../base/terminal.dart';
-import '../base/time.dart';
 import '../cache.dart';
 import '../globals.dart' as globals;
 import '../persistent_tool_state.dart';
@@ -87,7 +86,7 @@
     String workingDirectory = Cache.flutterRoot;
     if (argResults.wasParsed('working-directory')) {
       workingDirectory = stringArg('working-directory');
-      _flutterVersion = FlutterVersion(const SystemClock(), workingDirectory);
+      _flutterVersion = FlutterVersion(workingDirectory: workingDirectory);
     }
 
     final String currentChannel = _flutterVersion.channel;
diff --git a/packages/flutter_tools/lib/src/commands/upgrade.dart b/packages/flutter_tools/lib/src/commands/upgrade.dart
index e941d7c..5771d9b 100644
--- a/packages/flutter_tools/lib/src/commands/upgrade.dart
+++ b/packages/flutter_tools/lib/src/commands/upgrade.dart
@@ -14,7 +14,6 @@
 import '../globals.dart' as globals;
 import '../runner/flutter_command.dart';
 import '../version.dart';
-import 'channel.dart';
 
 class UpgradeCommand extends FlutterCommand {
   UpgradeCommand([UpgradeCommandRunner commandRunner])
@@ -67,7 +66,7 @@
       gitTagVersion: GitTagVersion.determine(globals.processUtils),
       flutterVersion: stringArg('working-directory') == null
         ? globals.flutterVersion
-        : FlutterVersion(const SystemClock(), _commandRunner.workingDirectory),
+        : FlutterVersion(clock: const SystemClock(), workingDirectory: _commandRunner.workingDirectory),
       verifyOnly: boolArg('verify-only'),
     );
   }
@@ -154,7 +153,6 @@
       );
     }
     recordState(flutterVersion);
-    await upgradeChannel(flutterVersion);
     await attemptReset(upstreamRevision);
     if (!testFlow) {
       await flutterUpgradeContinue();
@@ -258,15 +256,6 @@
     return revision;
   }
 
-  /// Attempts to upgrade the channel.
-  ///
-  /// If the user is on a deprecated channel, attempts to migrate them off of
-  /// it.
-  Future<void> upgradeChannel(FlutterVersion flutterVersion) async {
-    globals.printStatus('Upgrading Flutter from $workingDirectory...');
-    await ChannelCommand.upgradeChannel();
-  }
-
   /// Attempts a hard reset to the given revision.
   ///
   /// This is a reset instead of fast forward because if we are on a release
diff --git a/packages/flutter_tools/lib/src/context_runner.dart b/packages/flutter_tools/lib/src/context_runner.dart
index 2abcdee..fc65f44 100644
--- a/packages/flutter_tools/lib/src/context_runner.dart
+++ b/packages/flutter_tools/lib/src/context_runner.dart
@@ -186,7 +186,7 @@
         androidWorkflow: androidWorkflow,
       ),
       FeatureFlags: () => const FlutterFeatureFlags(),
-      FlutterVersion: () => FlutterVersion(const SystemClock()),
+      FlutterVersion: () => FlutterVersion(clock: const SystemClock()),
       FuchsiaArtifacts: () => FuchsiaArtifacts.find(),
       FuchsiaDeviceTools: () => FuchsiaDeviceTools(),
       FuchsiaSdk: () => FuchsiaSdk(),
diff --git a/packages/flutter_tools/lib/src/reporting/usage.dart b/packages/flutter_tools/lib/src/reporting/usage.dart
index cdff5ae..1ced397 100644
--- a/packages/flutter_tools/lib/src/reporting/usage.dart
+++ b/packages/flutter_tools/lib/src/reporting/usage.dart
@@ -423,8 +423,7 @@
         isFirstRun ||
         // Display the welcome message if we are not on master, and if the
         // persistent tool state instructs that we should.
-        (!globals.flutterVersion.isMaster &&
-        (globals.persistentToolState.redisplayWelcomeMessage ?? true))) {
+        (globals.persistentToolState.redisplayWelcomeMessage ?? true)) {
       _printWelcome();
       _printedWelcome = true;
       globals.persistentToolState.redisplayWelcomeMessage = false;
diff --git a/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart b/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart
index b3301f8..6f76704 100644
--- a/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart
+++ b/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart
@@ -232,13 +232,7 @@
           globals.flutterUsage.suppressAnalytics = true;
         }
 
-        try {
-          await globals.flutterVersion.ensureVersionFile();
-        } on FileSystemException catch (e) {
-          globals.printError('Failed to write the version file to the artifact cache: "$e".');
-          globals.printError('Please ensure you have permissions in the artifact cache directory.');
-          throwToolExit('Failed to write the version file');
-        }
+        globals.flutterVersion.ensureVersionFile();
         final bool machineFlag = topLevelResults['machine'] as bool;
         if (topLevelResults.command?.name != 'upgrade' && topLevelResults['version-check'] as bool && !machineFlag) {
           await globals.flutterVersion.checkFlutterVersionFreshness();
diff --git a/packages/flutter_tools/lib/src/version.dart b/packages/flutter_tools/lib/src/version.dart
index 3ec6bcd..6d679d3 100644
--- a/packages/flutter_tools/lib/src/version.dart
+++ b/packages/flutter_tools/lib/src/version.dart
@@ -16,17 +16,6 @@
 /// The flutter GitHub repository.
 String get _flutterGit => globals.platform.environment['FLUTTER_GIT_URL'] ?? 'https://github.com/flutter/flutter.git';
 
-/// This maps old branch names to the names of branches that replaced them.
-///
-/// For example, in early 2018 we changed from having an "alpha" branch to
-/// having a "dev" branch, so anyone using "alpha" now gets transitioned to
-/// "dev".
-const Map<String, String> kObsoleteBranches = <String, String>{
-  'alpha': 'dev',
-  'hackathon': 'dev',
-  'codelab': 'dev',
-};
-
 /// The names of each channel/branch in order of increasing stability.
 enum Channel {
   master,
@@ -67,7 +56,11 @@
   ///
   /// Call [fetchTagsAndUpdate] to update the version based on the latest tags
   /// available upstream.
-  FlutterVersion([this._clock = const SystemClock(), this._workingDirectory]) {
+  FlutterVersion({
+    SystemClock clock = const SystemClock(),
+    String workingDirectory,
+  }) : _clock = clock,
+      _workingDirectory = workingDirectory {
     _frameworkRevision = _runGit(
       gitLog(<String>['-n', '1', '--pretty=format:%H']).join(' '),
       globals.processUtils,
@@ -77,6 +70,9 @@
     _frameworkVersion = gitTagVersion.frameworkVersionFor(_frameworkRevision);
   }
 
+  final SystemClock _clock;
+  final String _workingDirectory;
+
   /// Fetches tags from the upstream Flutter repository and re-calculates the
   /// version.
   ///
@@ -88,21 +84,12 @@
     _frameworkVersion = gitTagVersion.frameworkVersionFor(_frameworkRevision);
   }
 
-  final SystemClock _clock;
-  final String _workingDirectory;
-
   String _repositoryUrl;
   String get repositoryUrl {
     final String _ = channel;
     return _repositoryUrl;
   }
 
-  /// Whether we are currently on the master branch.
-  bool get isMaster {
-    final String branchName = getBranchName();
-    return !<String>['dev', 'beta', 'stable'].contains(branchName);
-  }
-
   String _channel;
   /// The channel is the upstream branch.
   /// `master`, `dev`, `beta`, `stable`; or old ones, like `alpha`, `hackathon`, ...
@@ -161,9 +148,8 @@
   String get engineRevision => globals.cache.engineRevision;
   String get engineRevisionShort => _shortGitRevision(engineRevision);
 
-  Future<void> ensureVersionFile() {
+  void ensureVersionFile() {
     globals.fs.file(globals.fs.path.join(Cache.flutterRoot, 'version')).writeAsStringSync(_frameworkVersion);
-    return Future<void>.value();
   }
 
   @override
@@ -298,8 +284,7 @@
     }();
     if (redactUnknownBranches || _branch.isEmpty) {
       // Only return the branch names we know about; arbitrary branch names might contain PII.
-      if (!kOfficialChannels.contains(_branch) &&
-          !kObsoleteBranches.containsKey(_branch)) {
+      if (!kOfficialChannels.contains(_branch)) {
         return '[user-branch]';
       }
     }
diff --git a/packages/flutter_tools/test/commands.shard/permeable/upgrade_test.dart b/packages/flutter_tools/test/commands.shard/permeable/upgrade_test.dart
index 6910c31..3fbdb44 100644
--- a/packages/flutter_tools/test/commands.shard/permeable/upgrade_test.dart
+++ b/packages/flutter_tools/test/commands.shard/permeable/upgrade_test.dart
@@ -40,7 +40,7 @@
       fakeCommandRunner = FakeUpgradeCommandRunner();
       realCommandRunner = UpgradeCommandRunner();
       processManager = FakeProcessManager.list(<FakeCommand>[]);
-      fakeCommandRunner.willHaveUncomittedChanges = false;
+      fakeCommandRunner.willHaveUncommittedChanges = false;
       fakePlatform = FakePlatform()..environment = Map<String, String>.unmodifiable(<String, String>{
         'ENV1': 'irrelevant',
         'ENV2': 'irrelevant',
@@ -63,7 +63,7 @@
     });
 
     testUsingContext('throws tool exit with uncommitted changes', () async {
-      fakeCommandRunner.willHaveUncomittedChanges = true;
+      fakeCommandRunner.willHaveUncommittedChanges = true;
       final Future<FlutterCommandResult> result = fakeCommandRunner.runCommand(
         force: false,
         continueFlow: false,
@@ -290,7 +290,7 @@
       });
 
       testUsingContext('does not throw tool exit with uncommitted changes and force', () async {
-        fakeCommandRunner.willHaveUncomittedChanges = true;
+        fakeCommandRunner.willHaveUncommittedChanges = true;
 
         final Future<FlutterCommandResult> result = fakeCommandRunner.runCommand(
           force: true,
@@ -348,7 +348,7 @@
           ]);
           tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_upgrade_test.');
           flutterToolState = tempDir.childFile('.flutter_tool_state');
-          mockFlutterVersion = MockFlutterVersion(isStable: true);
+          mockFlutterVersion = MockFlutterVersion();
         });
 
         tearDown(() {
@@ -385,7 +385,7 @@
 }
 
 class FakeUpgradeCommandRunner extends UpgradeCommandRunner {
-  bool willHaveUncomittedChanges = false;
+  bool willHaveUncommittedChanges = false;
 
   bool alreadyUpToDate = false;
 
@@ -395,10 +395,7 @@
   Future<String> fetchRemoteRevision() async => remoteRevision;
 
   @override
-  Future<bool> hasUncommittedChanges() async => willHaveUncomittedChanges;
-
-  @override
-  Future<void> upgradeChannel(FlutterVersion flutterVersion) async {}
+  Future<bool> hasUncommittedChanges() async => willHaveUncommittedChanges;
 
   @override
   Future<void> attemptReset(String newRevision) async {}
diff --git a/packages/flutter_tools/test/general.shard/analytics_test.dart b/packages/flutter_tools/test/general.shard/analytics_test.dart
index 377f04c..5551845 100644
--- a/packages/flutter_tools/test/general.shard/analytics_test.dart
+++ b/packages/flutter_tools/test/general.shard/analytics_test.dart
@@ -70,7 +70,7 @@
 
       expect(count, 0);
     }, overrides: <Type, Generator>{
-      FlutterVersion: () => FlutterVersion(const SystemClock()),
+      FlutterVersion: () => FlutterVersion(clock: const SystemClock()),
       Usage: () => Usage(
         configDirOverride: tempDir.path,
         logFile: tempDir.childFile('analytics.log').path,
@@ -94,7 +94,7 @@
 
       expect(count, 0);
     }, overrides: <Type, Generator>{
-      FlutterVersion: () => FlutterVersion(const SystemClock()),
+      FlutterVersion: () => FlutterVersion(clock: const SystemClock()),
       Usage: () => Usage(
         configDirOverride: tempDir.path,
         logFile: tempDir.childFile('analytics.log').path,
@@ -112,7 +112,7 @@
 
       expect(globals.fs.file('test').readAsStringSync(), contains('$featuresKey: enable-web'));
     }, overrides: <Type, Generator>{
-      FlutterVersion: () => FlutterVersion(const SystemClock()),
+      FlutterVersion: () => FlutterVersion(clock: const SystemClock()),
       Config: () => mockFlutterConfig,
       Platform: () => FakePlatform(environment: <String, String>{
         'FLUTTER_ANALYTICS_LOG_FILE': 'test',
@@ -138,7 +138,7 @@
         contains('$featuresKey: enable-web,enable-linux-desktop,enable-macos-desktop'),
       );
     }, overrides: <Type, Generator>{
-      FlutterVersion: () => FlutterVersion(const SystemClock()),
+      FlutterVersion: () => FlutterVersion(clock: const SystemClock()),
       Config: () => mockFlutterConfig,
       Platform: () => FakePlatform(environment: <String, String>{
         'FLUTTER_ANALYTICS_LOG_FILE': 'test',
diff --git a/packages/flutter_tools/test/general.shard/runner/flutter_command_runner_test.dart b/packages/flutter_tools/test/general.shard/runner/flutter_command_runner_test.dart
index b187223..b2bda05 100644
--- a/packages/flutter_tools/test/general.shard/runner/flutter_command_runner_test.dart
+++ b/packages/flutter_tools/test/general.shard/runner/flutter_command_runner_test.dart
@@ -96,18 +96,6 @@
         Platform: () => platform,
       }, initializeFlutterRoot: false);
 
-      testUsingContext('throw tool exit if the version file cannot be written', () async {
-        final MockFlutterVersion version = globals.flutterVersion as MockFlutterVersion;
-        when(version.ensureVersionFile()).thenThrow(const FileSystemException());
-
-        expect(() async => await runner.run(<String>['dummy']), throwsToolExit());
-
-      }, overrides: <Type, Generator>{
-        FileSystem: () => fs,
-        ProcessManager: () => FakeProcessManager.any(),
-        Platform: () => platform,
-      }, initializeFlutterRoot: false);
-
     testUsingContext('Doesnt crash on invalid .packages file', () async {
       fs.file('pubspec.yaml').createSync();
       fs.file('.packages')
diff --git a/packages/flutter_tools/test/general.shard/version_test.dart b/packages/flutter_tools/test/general.shard/version_test.dart
index 5b922bc..3e69c5b 100644
--- a/packages/flutter_tools/test/general.shard/version_test.dart
+++ b/packages/flutter_tools/test/general.shard/version_test.dart
@@ -119,7 +119,7 @@
         _expectVersionMessage('');
         expect(processManager.hasRemainingExpectations, isFalse);
       }, overrides: <Type, Generator>{
-        FlutterVersion: () => FlutterVersion(_testClock),
+        FlutterVersion: () => FlutterVersion(clock: _testClock),
         ProcessManager: () => processManager,
         Cache: () => mockCache,
       });
@@ -143,7 +143,7 @@
         await version.checkFlutterVersionFreshness();
         _expectVersionMessage('');
       }, overrides: <Type, Generator>{
-        FlutterVersion: () => FlutterVersion(_testClock),
+        FlutterVersion: () => FlutterVersion(clock: _testClock),
         ProcessManager: () => mockProcessManager,
         Cache: () => mockCache,
       });
@@ -165,7 +165,7 @@
         await version.checkFlutterVersionFreshness();
         _expectVersionMessage(FlutterVersion.newVersionAvailableMessage());
       }, overrides: <Type, Generator>{
-        FlutterVersion: () => FlutterVersion(_testClock),
+        FlutterVersion: () => FlutterVersion(clock: _testClock),
         ProcessManager: () => mockProcessManager,
         Cache: () => mockCache,
       });
@@ -191,7 +191,7 @@
         await version.checkFlutterVersionFreshness();
         _expectVersionMessage('');
       }, overrides: <Type, Generator>{
-        FlutterVersion: () => FlutterVersion(_testClock),
+        FlutterVersion: () => FlutterVersion(clock: _testClock),
         ProcessManager: () => mockProcessManager,
         Cache: () => mockCache,
       });
@@ -222,7 +222,7 @@
         await version.checkFlutterVersionFreshness();
         _expectVersionMessage('');
       }, overrides: <Type, Generator>{
-        FlutterVersion: () => FlutterVersion(_testClock),
+        FlutterVersion: () => FlutterVersion(clock: _testClock),
         ProcessManager: () => mockProcessManager,
         Cache: () => mockCache,
       });
@@ -246,7 +246,7 @@
         await version.checkFlutterVersionFreshness();
         _expectVersionMessage(FlutterVersion.newVersionAvailableMessage());
       }, overrides: <Type, Generator>{
-        FlutterVersion: () => FlutterVersion(_testClock),
+        FlutterVersion: () => FlutterVersion(clock: _testClock),
         ProcessManager: () => mockProcessManager,
         Cache: () => mockCache,
       });
@@ -266,7 +266,7 @@
         await version.checkFlutterVersionFreshness();
         _expectVersionMessage('');
       }, overrides: <Type, Generator>{
-        FlutterVersion: () => FlutterVersion(_testClock),
+        FlutterVersion: () => FlutterVersion(clock: _testClock),
         ProcessManager: () => mockProcessManager,
         Cache: () => mockCache,
       });
@@ -286,7 +286,7 @@
         await version.checkFlutterVersionFreshness();
         _expectVersionMessage(FlutterVersion.versionOutOfDateMessage(_testClock.now().difference(getChannelOutOfDateVersion())));
       }, overrides: <Type, Generator>{
-        FlutterVersion: () => FlutterVersion(_testClock),
+        FlutterVersion: () => FlutterVersion(clock: _testClock),
         ProcessManager: () => mockProcessManager,
         Cache: () => mockCache,
       });
@@ -320,7 +320,7 @@
           workingDirectory: anyNamed('workingDirectory'),
         ));
       }, overrides: <Type, Generator>{
-        FlutterVersion: () => FlutterVersion(_testClock),
+        FlutterVersion: () => FlutterVersion(clock: _testClock),
         ProcessManager: () => mockProcessManager,
       });
     });
@@ -336,7 +336,7 @@
         fakeData(mockProcessManager, mockCache, channel: channel);
         _expectDefault(await VersionCheckStamp.load());
       }, overrides: <Type, Generator>{
-        FlutterVersion: () => FlutterVersion(_testClock),
+        FlutterVersion: () => FlutterVersion(clock: _testClock),
         ProcessManager: () => mockProcessManager,
         Cache: () => mockCache,
       });
@@ -345,7 +345,7 @@
         fakeData(mockProcessManager, mockCache, stampJson: '<', channel: channel);
         _expectDefault(await VersionCheckStamp.load());
       }, overrides: <Type, Generator>{
-        FlutterVersion: () => FlutterVersion(_testClock),
+        FlutterVersion: () => FlutterVersion(clock: _testClock),
         ProcessManager: () => mockProcessManager,
         Cache: () => mockCache,
       });
@@ -359,7 +359,7 @@
         );
         _expectDefault(await VersionCheckStamp.load());
       }, overrides: <Type, Generator>{
-        FlutterVersion: () => FlutterVersion(_testClock),
+        FlutterVersion: () => FlutterVersion(clock: _testClock),
         ProcessManager: () => mockProcessManager,
         Cache: () => mockCache,
       });
@@ -383,7 +383,7 @@
         expect(stamp.lastTimeVersionWasChecked, _testClock.ago(const Duration(days: 2)));
         expect(stamp.lastTimeWarningWasPrinted, _testClock.now());
       }, overrides: <Type, Generator>{
-        FlutterVersion: () => FlutterVersion(_testClock),
+        FlutterVersion: () => FlutterVersion(clock: _testClock),
         ProcessManager: () => mockProcessManager,
         Cache: () => mockCache,
       });
@@ -410,7 +410,7 @@
         expect(storedStamp.lastTimeVersionWasChecked, _testClock.ago(const Duration(days: 2)));
         expect(storedStamp.lastTimeWarningWasPrinted, _testClock.now());
       }, overrides: <Type, Generator>{
-        FlutterVersion: () => FlutterVersion(_testClock),
+        FlutterVersion: () => FlutterVersion(clock: _testClock),
         ProcessManager: () => mockProcessManager,
         Cache: () => mockCache,
       });
@@ -441,7 +441,7 @@
         expect(storedStamp.lastTimeVersionWasChecked, _testClock.ago(const Duration(days: 2)));
         expect(storedStamp.lastTimeWarningWasPrinted, _testClock.now());
       }, overrides: <Type, Generator>{
-        FlutterVersion: () => FlutterVersion(_testClock),
+        FlutterVersion: () => FlutterVersion(clock: _testClock),
         ProcessManager: () => mockProcessManager,
         Cache: () => mockCache,
       });
diff --git a/packages/flutter_tools/test/src/context.dart b/packages/flutter_tools/test/src/context.dart
index 0813ecc..b1616fe 100644
--- a/packages/flutter_tools/test/src/context.dart
+++ b/packages/flutter_tools/test/src/context.dart
@@ -419,14 +419,7 @@
   List<String> xcrunCommand() => <String>['xcrun'];
 }
 
-class MockFlutterVersion extends Mock implements FlutterVersion {
-  MockFlutterVersion({bool isStable = false}) : _isStable = isStable;
-
-  final bool _isStable;
-
-  @override
-  bool get isMaster => !_isStable;
-}
+class MockFlutterVersion extends Mock implements FlutterVersion {}
 
 class MockClock extends Mock implements SystemClock {}
 
diff --git a/packages/flutter_tools/test/src/testbed.dart b/packages/flutter_tools/test/src/testbed.dart
index f0f8a4c..44c2b87 100644
--- a/packages/flutter_tools/test/src/testbed.dart
+++ b/packages/flutter_tools/test/src/testbed.dart
@@ -710,9 +710,6 @@
   }
 
   @override
-  bool get isMaster => true;
-
-  @override
   String get repositoryUrl => null;
 
   @override