Bläddra i källkod

Renames checkout to switch & restore

Git 2.23.0 splits checkout into switch & restore
main
Eric Amodio 5 år sedan
förälder
incheckning
fe20f13ca9
5 ändrade filer med 329 tillägg och 298 borttagningar
  1. +42
    -16
      package.json
  2. +13
    -13
      src/commands/git/switch.ts
  3. +5
    -5
      src/commands/gitCommands.ts
  4. +14
    -9
      src/views/viewCommands.ts

+ 42
- 16
package.json Visa fil

@ -484,29 +484,29 @@
"gitlens.gitCommands.skipConfirmations": {
"type": "array",
"default": [
"checkout",
"fetch",
"stash-push"
"stash-push",
"switch"
],
"items": {
"type": "string",
"enum": [
"checkout",
"fetch",
"pull",
"push",
"stash-apply",
"stash-pop",
"stash-push"
"stash-push",
"switch"
],
"enumDescriptions": [
"Skips checkout command confirmation",
"Skips fetch command confirmation",
"Skips pull command confirmation",
"Skips push command confirmation",
"Skips stash apply command confirmation",
"Skips stash pop command confirmation",
"Skips stash push command confirmation"
"Skips stash push command confirmation",
"Skips switch command confirmation"
]
},
"minItems": 0,
@ -2414,8 +2414,26 @@
}
},
{
"command": "gitlens.views.checkout",
"title": "Checkout",
"command": "gitlens.views.restore",
"title": "Restore",
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-checkout.svg",
"light": "images/light/icon-checkout.svg"
}
},
{
"command": "gitlens.views.switchToBranch",
"title": "Switch to Branch",
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-checkout.svg",
"light": "images/light/icon-checkout.svg"
}
},
{
"command": "gitlens.views.switchToTag",
"title": "Switch to Tag",
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-checkout.svg",
@ -3431,7 +3449,15 @@
"when": "false"
},
{
"command": "gitlens.views.checkout",
"command": "gitlens.views.restore",
"when": "false"
},
{
"command": "gitlens.views.switchToBranch",
"when": "false"
},
{
"command": "gitlens.views.switchToTag",
"when": "false"
},
{
@ -4369,7 +4395,7 @@
"group": "inline@2"
},
{
"command": "gitlens.views.checkout",
"command": "gitlens.views.switchToBranch",
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b/",
"group": "inline@10"
},
@ -4395,8 +4421,8 @@
"group": "inline@98"
},
{
"command": "gitlens.views.checkout",
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?!.*?\\b\\+current\\b)/",
"command": "gitlens.views.switchToBranch",
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b/",
"group": "1_gitlens@1"
},
{
@ -4709,7 +4735,7 @@
"group": "5_gitlens_1@1"
},
{
"command": "gitlens.views.checkout",
"command": "gitlens.views.restore",
"when": "viewItem =~ /gitlens:file\\b((?=.*?\\b\\+committed\\b)|:results\\b)/",
"group": "5_gitlens_1@2"
},
@ -4719,7 +4745,7 @@
"group": "1_gitlens@1"
},
{
"command": "gitlens.views.checkout",
"command": "gitlens.views.restore",
"when": "!gitlens:readonly && viewItem == gitlens:file:stash",
"group": "1_gitlens@2"
},
@ -5076,12 +5102,12 @@
"group": "1_gitlens@2"
},
{
"command": "gitlens.views.checkout",
"command": "gitlens.views.switchToTag",
"when": "!gitlens:readonly && viewItem =~ /gitlens:tag\\b/",
"group": "inline@10"
},
{
"command": "gitlens.views.checkout",
"command": "gitlens.views.switchToTag",
"when": "!gitlens:readonly && viewItem =~ /gitlens:tag\\b/",
"group": "1_gitlens@1"
},

src/commands/git/checkout.ts → src/commands/git/switch.ts Visa fil

@ -17,16 +17,16 @@ interface State {
createBranch?: string;
}
export interface CheckoutGitCommandArgs {
readonly command: 'checkout';
export interface SwitchGitCommandArgs {
readonly command: 'switch';
state?: Partial<State>;
confirm?: boolean;
}
export class CheckoutGitCommand extends QuickCommandBase<State> {
constructor(args?: CheckoutGitCommandArgs) {
super('checkout', 'checkout', 'Checkout');
export class SwitchGitCommand extends QuickCommandBase<State> {
constructor(args?: SwitchGitCommandArgs) {
super('switch', 'switch', 'Switch');
if (args === undefined || args.state === undefined) return;
@ -50,7 +50,7 @@ export class CheckoutGitCommand extends QuickCommandBase {
return void (await window.withProgress(
{
location: ProgressLocation.Notification,
title: `Checking out ${
title: `Switching ${
state.repos.length === 1 ? state.repos[0].formattedName : `${state.repos.length} repositories`
} to ${state.branchOrTagOrRef.ref}`
},
@ -128,7 +128,7 @@ export class CheckoutGitCommand extends QuickCommandBase {
}`,
placeholder: `Choose a branch${
showTags ? ' or tag' : ''
} to checkout to${GlyphChars.Space.repeat(3)}(select or enter a reference)`,
} to switch to${GlyphChars.Space.repeat(3)}(select or enter a reference)`,
matchOnDescription: true,
items: items,
selectedItems: state.branchOrTagOrRef
@ -144,7 +144,7 @@ export class CheckoutGitCommand extends QuickCommandBase {
quickpick.placeholder = `Choose a branch${
showTags ? ' or tag' : ''
} to checkout to${GlyphChars.Space.repeat(3)}(select or enter a reference)`;
} to switch to${GlyphChars.Space.repeat(3)}(select or enter a reference)`;
quickpick.items = await getBranchesAndOrTags(
state.repos!,
@ -233,12 +233,12 @@ export class CheckoutGitCommand extends QuickCommandBase {
[
{
label: this.title,
description: `${state.createBranch ? `${state.createBranch} to ` : ''}${
state.branchOrTagOrRef.name
}`,
description: state.createBranch
? `${state.createBranch} (from ${state.branchOrTagOrRef.name}) `
: state.branchOrTagOrRef.name,
detail: `Will ${
state.createBranch ? `create ${state.createBranch} and` : ''
} checkout to ${state.branchOrTagOrRef.name} in ${
state.createBranch ? `create and switch to ${state.createBranch} (from ${state.branchOrTagOrRef.name})` : `switch to ${state.branchOrTagOrRef.name}`
} in ${
state.repos.length === 1
? state.repos[0].formattedName
: `${state.repos.length} repositories`

+ 5
- 5
src/commands/gitCommands.ts Visa fil

@ -11,7 +11,6 @@ import {
StepSelection
} from './quickCommand';
import { Directive, DirectiveQuickPickItem } from '../quickpicks';
import { CheckoutGitCommand, CheckoutGitCommandArgs } from './git/checkout';
import { CherryPickGitCommand } from './git/cherry-pick';
import { FetchGitCommand, FetchGitCommandArgs } from './git/fetch';
import { MergeGitCommand } from './git/merge';
@ -19,17 +18,18 @@ import { PullGitCommand, PullGitCommandArgs } from './git/pull';
import { PushGitCommand, PushGitCommandArgs } from './git/push';
import { RebaseGitCommand } from './git/rebase';
import { StashGitCommand, StashGitCommandArgs } from './git/stash';
import { SwitchGitCommand, SwitchGitCommandArgs } from './git/switch';
import { Container } from '../container';
import { configuration } from '../configuration';
const sanitizeLabel = /\$\(.+?\)|\W/g;
export type GitCommandsCommandArgs =
| CheckoutGitCommandArgs
| FetchGitCommandArgs
| PullGitCommandArgs
| PushGitCommandArgs
| StashGitCommandArgs;
| StashGitCommandArgs
| SwitchGitCommandArgs;
class PickCommandStep implements QuickPickStep {
readonly buttons = [];
@ -39,14 +39,14 @@ class PickCommandStep implements QuickPickStep {
constructor(args?: GitCommandsCommandArgs) {
this.items = [
new CheckoutGitCommand(args && args.command === 'checkout' ? args : undefined),
new CherryPickGitCommand(),
new MergeGitCommand(),
new FetchGitCommand(args && args.command === 'fetch' ? args : undefined),
new PullGitCommand(args && args.command === 'pull' ? args : undefined),
new PushGitCommand(args && args.command === 'push' ? args : undefined),
new RebaseGitCommand(),
new StashGitCommand(args && args.command === 'stash' ? args : undefined)
new StashGitCommand(args && args.command === 'stash' ? args : undefined),
new SwitchGitCommand(args && args.command === 'switch' ? args : undefined)
];
}

+ 14
- 9
src/views/viewCommands.ts Visa fil

@ -126,7 +126,9 @@ export class ViewCommands {
);
commands.registerCommand('gitlens.views.openChangedFileRevisions', this.openChangedFileRevisions, this);
commands.registerCommand('gitlens.views.applyChanges', this.applyChanges, this);
commands.registerCommand('gitlens.views.checkout', this.checkout, this);
commands.registerCommand('gitlens.views.restore', this.restore, this);
commands.registerCommand('gitlens.views.switchToBranch', this.switch, this);
commands.registerCommand('gitlens.views.switchToTag', this.switch, this);
commands.registerCommand('gitlens.views.addRemote', this.addRemote, this);
commands.registerCommand('gitlens.views.pruneRemote', this.pruneRemote, this);
@ -257,28 +259,31 @@ export class ViewCommands {
}
}
private async checkout(node: ViewRefNode | ViewRefFileNode) {
if (!(node instanceof ViewRefNode)) return undefined;
private async restore(node: ViewRefFileNode) {
if (!(node instanceof ViewRefFileNode)) return undefined;
if (node instanceof ViewRefFileNode) {
return Container.git.checkout(node.repoPath, node.ref, { fileName: node.fileName });
}
return Container.git.checkout(node.repoPath, node.ref, { fileName: node.fileName });
}
private async switch(node: ViewRefNode) {
if (!(node instanceof ViewRefNode)) return undefined;
const repo = await Container.git.getRepository(node.repoPath);
let args: GitCommandsCommandArgs;
if (node instanceof BranchNode) {
args = {
command: 'checkout',
command: 'switch',
state: { repos: [repo!], branchOrTagOrRef: node.branch.current ? undefined : node.branch }
};
}
else if (node instanceof TagNode) {
args = { command: 'checkout', state: { repos: [repo!], branchOrTagOrRef: node.tag } };
args = { command: 'switch', state: { repos: [repo!], branchOrTagOrRef: node.tag } };
}
else {
args = {
command: 'checkout',
command: 'switch',
state: { repos: [repo!], branchOrTagOrRef: { name: node.ref, ref: node.ref } }
};
}

Laddar…
Avbryt
Spara