@@ -70,8 +70,8 @@ export class PullRequestOverviewPanel {
70
70
} , this , this . _disposables ) ;
71
71
72
72
// Handle messages from the webview
73
- this . _panel . webview . onDidReceiveMessage ( message => {
74
- this . _onDidReceiveMessage ( message ) ;
73
+ this . _panel . webview . onDidReceiveMessage ( async message => {
74
+ await this . _onDidReceiveMessage ( message ) ;
75
75
} , null , this . _disposables ) ;
76
76
77
77
this . _pullRequestManager . onDidChangeActivePullRequest ( _ => {
@@ -155,7 +155,7 @@ export class PullRequestOverviewPanel {
155
155
}
156
156
}
157
157
158
- private _onDidReceiveMessage ( message ) {
158
+ private async _onDidReceiveMessage ( message ) {
159
159
switch ( message . command ) {
160
160
case 'alert' :
161
161
vscode . window . showErrorMessage ( message . text ) ;
@@ -174,9 +174,22 @@ export class PullRequestOverviewPanel {
174
174
return ;
175
175
case 'pr.checkout-default-branch' :
176
176
// This should be updated for multi-root support and consume the git extension API if possible
177
- exec ( [ 'checkout ' , message . branch || 'master '] , {
177
+ const result = await exec ( [ 'rev-parse ' , '--symbolic-full-name' , '@{-1} '] , {
178
178
cwd : vscode . workspace . rootPath
179
179
} ) ;
180
+
181
+ if ( result ) {
182
+ const branchFullName = result . stdout . trim ( ) ;
183
+
184
+ if ( `refs/heads/${ message . branch } ` === branchFullName ) {
185
+ await exec ( [ 'checkout' , message . branch ] , {
186
+ cwd : vscode . workspace . rootPath
187
+ } ) ;
188
+ } else {
189
+ await vscode . commands . executeCommand ( 'git.checkout' )
190
+ }
191
+ }
192
+
180
193
return ;
181
194
case 'pr.comment' :
182
195
const text = message . text ;
0 commit comments