Browse Source

Adds checkout to current branch w/ picker

main
Eric Amodio 5 years ago
parent
commit
345be49d7b
3 changed files with 41 additions and 16 deletions
  1. +1
    -1
      package.json
  2. +12
    -0
      src/quickpicks/referencesQuickPick.ts
  3. +28
    -15
      src/views/viewCommands.ts

+ 1
- 1
package.json View File

@ -4254,7 +4254,7 @@
}, },
{ {
"command": "gitlens.views.checkout", "command": "gitlens.views.checkout",
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?!.*?\\b\\+current\\b)/",
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch/",
"group": "inline@10" "group": "inline@10"
}, },
{ {

+ 12
- 0
src/quickpicks/referencesQuickPick.ts View File

@ -25,6 +25,18 @@ export class ReferencesQuickPick {
async show( async show(
placeHolder: string, placeHolder: string,
options?: Exclude<ReferencesQuickPickOptions, CommandQuickPickItem> & { include: 'branches' }
): Promise<BranchQuickPickItem | undefined>;
async show(
placeHolder: string,
options?: Exclude<ReferencesQuickPickOptions, CommandQuickPickItem> & { include: 'tags' }
): Promise<TagQuickPickItem | undefined>;
async show(
placeHolder: string,
options?: Exclude<ReferencesQuickPickOptions, CommandQuickPickItem>
): Promise<ReferencesQuickPickItem | undefined>;
async show(
placeHolder: string,
options: ReferencesQuickPickOptions = { checkmarks: true } options: ReferencesQuickPickOptions = { checkmarks: true }
): Promise<ReferencesQuickPickItem | CommandQuickPickItem | undefined> { ): Promise<ReferencesQuickPickItem | CommandQuickPickItem | undefined> {
const cancellation = new CancellationTokenSource(); const cancellation = new CancellationTokenSource();

+ 28
- 15
src/views/viewCommands.ts View File

@ -45,6 +45,7 @@ import {
} from './nodes'; } from './nodes';
import { Strings } from '../system/string'; import { Strings } from '../system/string';
import { runGitCommandInTerminal } from '../terminal'; import { runGitCommandInTerminal } from '../terminal';
import { ReferencesQuickPick } from '../quickpicks';
interface CompareSelectedInfo { interface CompareSelectedInfo {
ref: string; ref: string;
@ -243,25 +244,37 @@ export class ViewCommands {
return Container.git.checkout(node.repoPath, node.ref, { fileName: node.fileName }); 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); return Container.git.checkout(node.repoPath, node.ref);

Loading…
Cancel
Save