[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]';
       }
     }