Unverified Commit 91a85ac2 authored by Todd Volkert's avatar Todd Volkert Committed by GitHub

Fetch upstream refs before checking out branch in ChannelCommand (#14896)

https://github.com/flutter/flutter/issues/14893
parent 758c221d
...@@ -92,25 +92,34 @@ class ChannelCommand extends FlutterCommand { ...@@ -92,25 +92,34 @@ class ChannelCommand extends FlutterCommand {
} }
static Future<Null> _checkout(String branchName) async { static Future<Null> _checkout(String branchName) async {
// Get latest refs from upstream.
int result = await runCommandAndStreamOutput( int result = await runCommandAndStreamOutput(
<String>['git', 'show-ref', '--verify', '--quiet', 'refs/heads/$branchName'], <String>['git', 'fetch'],
workingDirectory: Cache.flutterRoot, workingDirectory: Cache.flutterRoot,
prefix: 'git: ', prefix: 'git: ',
); );
if (result == 0) { if (result == 0) {
// branch already exists, try just switching to it
result = await runCommandAndStreamOutput(
<String>['git', 'checkout', branchName],
workingDirectory: Cache.flutterRoot,
prefix: 'git: ',
);
} else {
// branch does not exist, we have to create it
result = await runCommandAndStreamOutput( result = await runCommandAndStreamOutput(
<String>['git', 'checkout', '--track', '-b', branchName, 'origin/$branchName'], <String>['git', 'show-ref', '--verify', '--quiet', 'refs/heads/$branchName'],
workingDirectory: Cache.flutterRoot, workingDirectory: Cache.flutterRoot,
prefix: 'git: ', prefix: 'git: ',
); );
if (result == 0) {
// branch already exists, try just switching to it
result = await runCommandAndStreamOutput(
<String>['git', 'checkout', branchName],
workingDirectory: Cache.flutterRoot,
prefix: 'git: ',
);
} else {
// branch does not exist, we have to create it
result = await runCommandAndStreamOutput(
<String>['git', 'checkout', '--track', '-b', branchName, 'origin/$branchName'],
workingDirectory: Cache.flutterRoot,
prefix: 'git: ',
);
}
} }
if (result != 0) if (result != 0)
throwToolExit('Switching channels failed with error code $result.', exitCode: result); throwToolExit('Switching channels failed with error code $result.', exitCode: result);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment