Unverified Commit a441a403 authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Fix the channel-switching logic (#14507)

parent 66ecfb02
...@@ -92,11 +92,26 @@ class ChannelCommand extends FlutterCommand { ...@@ -92,11 +92,26 @@ class ChannelCommand extends FlutterCommand {
} }
static Future<Null> _checkout(String branchName) async { static Future<Null> _checkout(String branchName) async {
final int result = await runCommandAndStreamOutput( int result = await runCommandAndStreamOutput(
<String>['git', 'checkout', '-b', 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