[flutter_tools] Reland "Make upgrade only work with standard remotes" (#87731)
This commit is contained in:
@@ -116,7 +116,7 @@ class UpgradeCommandRunner {
|
||||
@required bool testFlow,
|
||||
@required bool verifyOnly,
|
||||
}) async {
|
||||
final FlutterVersion upstreamVersion = await fetchLatestVersion();
|
||||
final FlutterVersion upstreamVersion = await fetchLatestVersion(localVersion: flutterVersion);
|
||||
if (flutterVersion.frameworkRevision == upstreamVersion.frameworkRevision) {
|
||||
globals.printStatus('Flutter is already up to date on channel ${flutterVersion.channel}');
|
||||
globals.printStatus('$flutterVersion');
|
||||
@@ -225,10 +225,79 @@ class UpgradeCommandRunner {
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks if the Flutter git repository is tracking a standard remote.
|
||||
///
|
||||
/// A "standard remote" is one having the same url as [globals.flutterGit].
|
||||
/// The upgrade process only supports standard remotes.
|
||||
///
|
||||
/// Exits tool if the tracking remote is not standard.
|
||||
void verifyStandardRemote(FlutterVersion localVersion) {
|
||||
// If repositoryUrl of the local version is null, exit
|
||||
if (localVersion.repositoryUrl == null) {
|
||||
throwToolExit(
|
||||
'Unable to upgrade Flutter: The tool could not determine the remote '
|
||||
'upstream which is being tracked by the SDK.\n'
|
||||
'Re-install Flutter by going to $_flutterInstallDocs.'
|
||||
);
|
||||
}
|
||||
|
||||
// Strip `.git` suffix before comparing the remotes
|
||||
final String trackingUrl = stripDotGit(localVersion.repositoryUrl);
|
||||
final String flutterGitUrl = stripDotGit(globals.flutterGit);
|
||||
|
||||
// Exempt the official flutter git SSH remote from this check
|
||||
if (trackingUrl == 'git@github.com:flutter/flutter') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (trackingUrl != flutterGitUrl) {
|
||||
if (globals.platform.environment.containsKey('FLUTTER_GIT_URL')) {
|
||||
// If `FLUTTER_GIT_URL` is set, inform the user to either remove the
|
||||
// `FLUTTER_GIT_URL` environment variable or set it to the current
|
||||
// tracking remote to continue.
|
||||
throwToolExit(
|
||||
'Unable to upgrade Flutter: The Flutter SDK is tracking '
|
||||
'"${localVersion.repositoryUrl}" but "FLUTTER_GIT_URL" is set to '
|
||||
'"${globals.flutterGit}".\n'
|
||||
'Either remove "FLUTTER_GIT_URL" from the environment or set it to '
|
||||
'"${localVersion.repositoryUrl}", and retry. '
|
||||
'Alternatively, re-install Flutter by going to $_flutterInstallDocs.\n'
|
||||
'If this is intentional, it is recommended to use "git" directly to '
|
||||
'keep Flutter SDK up-to date.'
|
||||
);
|
||||
}
|
||||
// If `FLUTTER_GIT_URL` is unset, inform that the user has to set the
|
||||
// environment variable to continue.
|
||||
throwToolExit(
|
||||
'Unable to upgrade Flutter: The Flutter SDK is tracking a non-standard '
|
||||
'remote "${localVersion.repositoryUrl}".\n'
|
||||
'Set the environment variable "FLUTTER_GIT_URL" to '
|
||||
'"${localVersion.repositoryUrl}", and retry. '
|
||||
'Alternatively, re-install Flutter by going to $_flutterInstallDocs.\n'
|
||||
'If this is intentional, it is recommended to use "git" directly to '
|
||||
'keep Flutter SDK up-to date.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Strips ".git" suffix from a given string, preferably an url.
|
||||
// For example, changes 'https://github.com/flutter/flutter.git' to 'https://github.com/flutter/flutter'.
|
||||
// URLs without ".git" suffix will remain unaffected.
|
||||
String stripDotGit(String url) {
|
||||
final RegExp pattern = RegExp(r'(.*)(\.git)$');
|
||||
final RegExpMatch match = pattern.firstMatch(url);
|
||||
if (match == null) {
|
||||
return url;
|
||||
}
|
||||
return match.group(1);
|
||||
}
|
||||
|
||||
/// Returns the remote HEAD flutter version.
|
||||
///
|
||||
/// Exits tool if HEAD isn't pointing to a branch, or there is no upstream.
|
||||
Future<FlutterVersion> fetchLatestVersion() async {
|
||||
Future<FlutterVersion> fetchLatestVersion({
|
||||
@required FlutterVersion localVersion,
|
||||
}) async {
|
||||
String revision;
|
||||
try {
|
||||
// Fetch upstream branch's commits and tags
|
||||
@@ -263,6 +332,7 @@ class UpgradeCommandRunner {
|
||||
throwToolExit(errorString);
|
||||
}
|
||||
}
|
||||
verifyStandardRemote(localVersion);
|
||||
return FlutterVersion(workingDirectory: workingDirectory, frameworkRevision: revision);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user