Skip to content

Commit 4febf5b

Browse files
authored
Check whether the version in flutter-candidate.txt is a tag or a commit hash (#7993)
Follow-up to #7989 Fixes error running `devtools_tool update-flutter-sdk` when the Flutter version is a commit hash: ``` ~/develop/devtools/packages/devtools_app/ [ext-settings-button*] devtools_tool update-flutter-sdk --use-cache Using Flutter SDK from /Users/kenzieschmoll/develop/devtools/tool/flutter-sdk Updating to Flutter version from cache: tags/1c77696615558bf8f9fa7a6e2a473f438f1c03ca Updating Flutter at /Users/kenzieschmoll/develop/devtools/tool/flutter-sdk /Users/kenzieschmoll/develop/devtools/tool/flutter-sdk > git fetch /Users/kenzieschmoll/develop/devtools/tool/flutter-sdk > git checkout tags/1c77696615558bf8f9fa7a6e2a473f438f1c03ca -f error: pathspec 'tags/1c77696615558bf8f9fa7a6e2a473f438f1c03ca' did not match any file(s) known to git ProcessException: Failed with exit code: 1. Command: git checkout tags/1c77696615558bf8f9fa7a6e2a473f438f1c03ca -f ```
1 parent 8f515f8 commit 4febf5b

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

tool/lib/commands/update_flutter_sdk.dart

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import '../utils.dart';
1414
const _updateOnPath = 'update-on-path';
1515
const _useCacheFlag = 'use-cache';
1616

17+
final _flutterPreReleaseTagRegExp = RegExp(r'[0-9]+.[0-9]+.0-[0-9]+.0.pre');
18+
1719
/// This command updates the the Flutter SDK contained in the 'tool/' directory
1820
/// to the latest Flutter candidate branch.
1921
///
@@ -79,12 +81,18 @@ class UpdateFlutterSdkCommand extends Command {
7981
final repo = DevToolsRepo.getInstance();
8082
final processManager = ProcessManager();
8183

82-
final String flutterTag;
84+
final String? flutterVersion;
85+
8386
if (useCachedVersion) {
84-
flutterTag =
85-
'tags/${repo.readFile(Uri.parse('flutter-candidate.txt')).trim()}';
87+
final versionStr =
88+
repo.readFile(Uri.parse('flutter-candidate.txt')).trim();
89+
// If the version string doesn't match the expected pattern for a
90+
// pre-release tag, then assume it's a commit hash:
91+
flutterVersion = _flutterPreReleaseTagRegExp.hasMatch(versionStr)
92+
? 'tags/$versionStr'
93+
: versionStr;
8694
} else {
87-
flutterTag = (await processManager.runProcess(
95+
flutterVersion = (await processManager.runProcess(
8896
CliCommand('sh', ['latest_flutter_candidate.sh']),
8997
workingDirectory: repo.toolDirectoryPath,
9098
))
@@ -95,7 +103,7 @@ class UpdateFlutterSdkCommand extends Command {
95103

96104
log.stdout(
97105
'Updating to Flutter version '
98-
'${useCachedVersion ? 'from cache' : 'from upstream'}: $flutterTag ',
106+
'${useCachedVersion ? 'from cache' : 'from upstream'}: $flutterVersion',
99107
);
100108

101109
final flutterSdkDirName = repo.sdkDirectoryName;
@@ -120,7 +128,7 @@ class UpdateFlutterSdkCommand extends Command {
120128
CliCommand.git(['fetch', 'upstream']),
121129
CliCommand.git(['checkout', 'upstream/master']),
122130
CliCommand.git(['reset', '--hard', 'upstream/master']),
123-
CliCommand.git(['checkout', flutterTag, '-f']),
131+
CliCommand.git(['checkout', flutterVersion, '-f']),
124132
CliCommand.flutter(['--version']),
125133
],
126134
workingDirectory: pathSdk.sdkPath,
@@ -134,7 +142,7 @@ class UpdateFlutterSdkCommand extends Command {
134142
await processManager.runAll(
135143
commands: [
136144
CliCommand.git(['fetch']),
137-
CliCommand.git(['checkout', flutterTag, '-f']),
145+
CliCommand.git(['checkout', flutterVersion, '-f']),
138146
CliCommand.flutter(['--version']),
139147
],
140148
workingDirectory: toolSdkPath,
@@ -149,7 +157,7 @@ class UpdateFlutterSdkCommand extends Command {
149157
);
150158
await processManager.runAll(
151159
commands: [
152-
CliCommand.git(['checkout', flutterTag, '-f']),
160+
CliCommand.git(['checkout', flutterVersion, '-f']),
153161
CliCommand.flutter(['--version']),
154162
],
155163
workingDirectory: toolSdkPath,

0 commit comments

Comments
 (0)