Skip to content

Commit 15e81df

Browse files
committed
Open branch picker when the last branch is not default branch
1 parent 454cfe4 commit 15e81df

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

preview-src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function setTitleHTML(pr: any) {
7171
<h2>${pr.title} (<a href=${pr.url}>#${pr.number}</a>) </h2>
7272
<div class="button-group">
7373
<button id="${ElementIds.Checkout}" aria-live="polite"></button>
74-
<button id="${ElementIds.CheckoutDefaultBranch}" aria-live="polite">Checkout ${pr.repositoryDefaultBranch}</button>
74+
<button id="${ElementIds.CheckoutDefaultBranch}" aria-live="polite">Exit Review Mode</button>
7575
</div>
7676
</div>
7777
<div class="subtitle">

src/github/pullRequestOverview.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ export class PullRequestOverviewPanel {
7070
}, this, this._disposables);
7171

7272
// 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);
7575
}, null, this._disposables);
7676

7777
this._pullRequestManager.onDidChangeActivePullRequest(_ => {
@@ -155,7 +155,7 @@ export class PullRequestOverviewPanel {
155155
}
156156
}
157157

158-
private _onDidReceiveMessage(message) {
158+
private async _onDidReceiveMessage(message) {
159159
switch (message.command) {
160160
case 'alert':
161161
vscode.window.showErrorMessage(message.text);
@@ -174,9 +174,22 @@ export class PullRequestOverviewPanel {
174174
return;
175175
case 'pr.checkout-default-branch':
176176
// 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}'], {
178178
cwd: vscode.workspace.rootPath
179179
});
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+
180193
return;
181194
case 'pr.comment':
182195
const text = message.text;

0 commit comments

Comments
 (0)