Pārlūkot izejas kodu

Adds checkout to current branch w/ picker

main
Eric Amodio pirms 5 gadiem
vecāks
revīzija
345be49d7b
3 mainītis faili ar 41 papildinājumiem un 16 dzēšanām
  1. +1
    -1
      package.json
  2. +12
    -0
      src/quickpicks/referencesQuickPick.ts
  3. +28
    -15
      src/views/viewCommands.ts

+ 1
- 1
package.json Parādīt failu

@ -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"
},
{

+ 12
- 0
src/quickpicks/referencesQuickPick.ts Parādīt failu

@ -25,6 +25,18 @@ export class ReferencesQuickPick {
async show(
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 }
): Promise<ReferencesQuickPickItem | CommandQuickPickItem | undefined> {
const cancellation = new CancellationTokenSource();

+ 28
- 15
src/views/viewCommands.ts Parādīt failu

@ -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);

Notiek ielāde…
Atcelt
Saglabāt