diff --git a/package.json b/package.json index a63ad1b..dbd328b 100644 --- a/package.json +++ b/package.json @@ -4254,7 +4254,7 @@ }, { "command": "gitlens.views.checkout", - "when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?!.*?\\b\\+current\\b)/", + "when": "!gitlens:readonly && viewItem =~ /gitlens:branch/", "group": "inline@10" }, { diff --git a/src/quickpicks/referencesQuickPick.ts b/src/quickpicks/referencesQuickPick.ts index 5b5c484..a181e39 100644 --- a/src/quickpicks/referencesQuickPick.ts +++ b/src/quickpicks/referencesQuickPick.ts @@ -25,6 +25,18 @@ export class ReferencesQuickPick { async show( placeHolder: string, + options?: Exclude & { include: 'branches' } + ): Promise; + async show( + placeHolder: string, + options?: Exclude & { include: 'tags' } + ): Promise; + async show( + placeHolder: string, + options?: Exclude + ): Promise; + async show( + placeHolder: string, options: ReferencesQuickPickOptions = { checkmarks: true } ): Promise { const cancellation = new CancellationTokenSource(); diff --git a/src/views/viewCommands.ts b/src/views/viewCommands.ts index b9df13a..de3ae6e 100644 --- a/src/views/viewCommands.ts +++ b/src/views/viewCommands.ts @@ -45,6 +45,7 @@ import { } from './nodes'; import { Strings } from '../system/string'; import { runGitCommandInTerminal } from '../terminal'; +import { ReferencesQuickPick } from '../quickpicks'; interface CompareSelectedInfo { ref: string; @@ -243,25 +244,37 @@ export class ViewCommands { return Container.git.checkout(node.repoPath, node.ref, { fileName: node.fileName }); } - if (node instanceof BranchNode && node.branch.remote) { - const branches = await Container.git.getBranches(node.repoPath, { - filter: b => { - return b.tracking === node.branch.name; - } - }); + if (node instanceof BranchNode) { + let branch = node.branch; + if (branch.current) { + const pick = await new ReferencesQuickPick(node.repoPath).show('Choose a branch to check out to', { checkmarks: false, filterBranches: b => !b.current, include: 'branches' }); + if (pick === undefined) return undefined; - if (branches.length !== 0) { - return Container.git.checkout(node.repoPath, branches[0].ref); + branch = pick.item; } - const name = await window.showInputBox({ - prompt: "Please provide a name for the local branch (Press 'Enter' to confirm or 'Escape' to cancel)", - placeHolder: 'Local branch name', - value: node.branch.getName() - }); - if (name === undefined || name.length === 0) return undefined; + if (branch.remote) { + const branches = await Container.git.getBranches(node.repoPath, { + filter: b => { + return b.tracking === branch.name; + } + }); + + if (branches.length !== 0) { + return Container.git.checkout(node.repoPath, branches[0].ref); + } + + const name = await window.showInputBox({ + prompt: "Please provide a name for the local branch (Press 'Enter' to confirm or 'Escape' to cancel)", + placeHolder: 'Local branch name', + value: branch.getName() + }); + if (name === undefined || name.length === 0) return undefined; + + return Container.git.checkout(node.repoPath, branch.ref, { createBranch: name }); + } - return Container.git.checkout(node.repoPath, node.ref, { createBranch: name }); + return Container.git.checkout(branch.repoPath, branch.ref); } return Container.git.checkout(node.repoPath, node.ref);