Skip to content

Commit

Permalink
Check whether the version in flutter-candidate.txt is a tag or a comm…
Browse files Browse the repository at this point in the history
…it 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
```
  • Loading branch information
elliette authored Jun 26, 2024
1 parent 8f515f8 commit 4febf5b
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions tool/lib/commands/update_flutter_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import '../utils.dart';
const _updateOnPath = 'update-on-path';
const _useCacheFlag = 'use-cache';

final _flutterPreReleaseTagRegExp = RegExp(r'[0-9]+.[0-9]+.0-[0-9]+.0.pre');

/// This command updates the the Flutter SDK contained in the 'tool/' directory
/// to the latest Flutter candidate branch.
///
Expand Down Expand Up @@ -79,12 +81,18 @@ class UpdateFlutterSdkCommand extends Command {
final repo = DevToolsRepo.getInstance();
final processManager = ProcessManager();

final String flutterTag;
final String? flutterVersion;

if (useCachedVersion) {
flutterTag =
'tags/${repo.readFile(Uri.parse('flutter-candidate.txt')).trim()}';
final versionStr =
repo.readFile(Uri.parse('flutter-candidate.txt')).trim();
// If the version string doesn't match the expected pattern for a
// pre-release tag, then assume it's a commit hash:
flutterVersion = _flutterPreReleaseTagRegExp.hasMatch(versionStr)
? 'tags/$versionStr'
: versionStr;
} else {
flutterTag = (await processManager.runProcess(
flutterVersion = (await processManager.runProcess(
CliCommand('sh', ['latest_flutter_candidate.sh']),
workingDirectory: repo.toolDirectoryPath,
))
Expand All @@ -95,7 +103,7 @@ class UpdateFlutterSdkCommand extends Command {

log.stdout(
'Updating to Flutter version '
'${useCachedVersion ? 'from cache' : 'from upstream'}: $flutterTag ',
'${useCachedVersion ? 'from cache' : 'from upstream'}: $flutterVersion',
);

final flutterSdkDirName = repo.sdkDirectoryName;
Expand All @@ -120,7 +128,7 @@ class UpdateFlutterSdkCommand extends Command {
CliCommand.git(['fetch', 'upstream']),
CliCommand.git(['checkout', 'upstream/master']),
CliCommand.git(['reset', '--hard', 'upstream/master']),
CliCommand.git(['checkout', flutterTag, '-f']),
CliCommand.git(['checkout', flutterVersion, '-f']),
CliCommand.flutter(['--version']),
],
workingDirectory: pathSdk.sdkPath,
Expand All @@ -134,7 +142,7 @@ class UpdateFlutterSdkCommand extends Command {
await processManager.runAll(
commands: [
CliCommand.git(['fetch']),
CliCommand.git(['checkout', flutterTag, '-f']),
CliCommand.git(['checkout', flutterVersion, '-f']),
CliCommand.flutter(['--version']),
],
workingDirectory: toolSdkPath,
Expand All @@ -149,7 +157,7 @@ class UpdateFlutterSdkCommand extends Command {
);
await processManager.runAll(
commands: [
CliCommand.git(['checkout', flutterTag, '-f']),
CliCommand.git(['checkout', flutterVersion, '-f']),
CliCommand.flutter(['--version']),
],
workingDirectory: toolSdkPath,
Expand Down

0 comments on commit 4febf5b

Please sign in to comment.