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

https://github.com/flutter/flutter/issues/14893
This commit is contained in:
Todd Volkert 2018-02-26 15:55:28 -08:00 committed by GitHub
parent 758c221dc3
commit 91a85ac249
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -92,25 +92,34 @@ class ChannelCommand extends FlutterCommand {
}
static Future<Null> _checkout(String branchName) async {
// Get latest refs from upstream.
int result = await runCommandAndStreamOutput(
<String>['git', 'show-ref', '--verify', '--quiet', 'refs/heads/$branchName'],
<String>['git', 'fetch'],
workingDirectory: Cache.flutterRoot,
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'],
<String>['git', 'show-ref', '--verify', '--quiet', 'refs/heads/$branchName'],
workingDirectory: Cache.flutterRoot,
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)
throwToolExit('Switching channels failed with error code $result.', exitCode: result);