Procházet zdrojové kódy

Adds stash changes command to working tree files

main
Eric Amodio před 6 roky
rodič
revize
88fc0bfa65
4 změnil soubory, kde provedl 35 přidání a 47 odebrání
  1. +6
    -0
      package.json
  2. +9
    -27
      src/commands/stashApply.ts
  3. +19
    -18
      src/commands/stashSave.ts
  4. +1
    -2
      src/git/git.ts

+ 6
- 0
package.json Zobrazit soubor

@ -3245,6 +3245,12 @@
"when": "viewItem =~ /gitlens:file\\b.*:staged\\b/",
"group": "1_gitlens@1"
},
{
"command": "gitlens.stashSave",
"when": "viewItem =~ /gitlens:file\\b.*:(un)?staged\\b/",
"group": "1_gitlens@2"
},
{
"command": "gitlens.explorers.openChanges",
"when": "viewItem =~ /gitlens:file\\b/",
"group": "2_gitlens@1"

+ 9
- 27
src/commands/stashApply.ts Zobrazit soubor

@ -5,9 +5,9 @@ import { Container } from '../container';
import { GitStashCommit } from '../git/gitService';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { CommandQuickPickItem, RepositoriesQuickPick, StashListQuickPick } from '../quickpicks';
import { CommandQuickPickItem, StashListQuickPick } from '../quickpicks';
import { Strings } from '../system';
import { Command, CommandContext, Commands, isCommandViewContextWithCommit } from './common';
import { Command, CommandContext, Commands, getRepoPathOrPrompt, isCommandViewContextWithCommit } from './common';
export interface StashApplyCommandArgs {
confirm?: boolean;
@ -39,30 +39,12 @@ export class StashApplyCommand extends Command {
args = { ...args };
if (args.stashItem === undefined || args.stashItem.stashName === undefined) {
let goBackToRepositoriesCommand: CommandQuickPickItem | undefined;
let repoPath = await Container.git.getActiveRepoPath();
if (!repoPath) {
const pick = await RepositoriesQuickPick.show(
`Apply stashed changes from which repository${GlyphChars.Ellipsis}`,
args.goBackCommand
);
if (pick instanceof CommandQuickPickItem) return pick.execute();
if (pick === undefined) {
return args.goBackCommand === undefined ? undefined : args.goBackCommand.execute();
}
goBackToRepositoriesCommand = new CommandQuickPickItem(
{
label: `go back ${GlyphChars.ArrowBack}`,
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} to pick another repository`
},
Commands.StashApply,
[args]
);
repoPath = pick.repoPath;
}
const repoPath = await getRepoPathOrPrompt(
undefined,
`Apply stashed changes from which repository${GlyphChars.Ellipsis}`,
args.goBackCommand
);
if (!repoPath) return undefined;
const progressCancellation = StashListQuickPick.showProgress('apply');
@ -85,7 +67,7 @@ export class StashApplyCommand extends Command {
stash,
'apply',
progressCancellation,
goBackToRepositoriesCommand || args.goBackCommand,
args.goBackCommand,
currentCommand
);
if (pick instanceof CommandQuickPickItem) return pick.execute();

+ 19
- 18
src/commands/stashSave.ts Zobrazit soubor

@ -2,10 +2,12 @@
import { InputBoxOptions, Uri, window } from 'vscode';
import { GlyphChars } from '../constants';
import { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { CommandQuickPickItem, RepositoriesQuickPick } from '../quickpicks';
import { Command, CommandContext, Commands } from './common';
import { CommandQuickPickItem } from '../quickpicks';
import { StatusFileNode } from '../views/nodes';
import { Command, CommandContext, Commands, getRepoPathOrPrompt } from './common';
export interface StashSaveCommandArgs {
message?: string;
@ -20,36 +22,35 @@ export class StashSaveCommand extends Command {
}
protected async preExecute(context: CommandContext, args: StashSaveCommandArgs = {}): Promise<any> {
if (context.type === 'scm-states') {
if (context.type === 'view') {
args = { ...args };
if (context.node instanceof StatusFileNode) {
args.uris = [GitUri.fromFile(context.node.file, context.node.repoPath)];
}
}
else if (context.type === 'scm-states') {
args = { ...args };
args.uris = context.scmResourceStates.map(s => s.resourceUri);
return this.execute(args);
}
if (context.type === 'scm-groups') {
else if (context.type === 'scm-groups') {
args = { ...args };
args.uris = context.scmResourceGroups.reduce<Uri[]>(
(a, b) => a.concat(b.resourceStates.map(s => s.resourceUri)),
[]
);
return this.execute(args);
}
return this.execute(args);
}
async execute(args: StashSaveCommandArgs = {}) {
let repoPath = await Container.git.getHighlanderRepoPath();
if (!repoPath) {
const pick = await RepositoriesQuickPick.show(
`Stash changes for which repository${GlyphChars.Ellipsis}`,
args.goBackCommand
);
if (pick instanceof CommandQuickPickItem) return pick.execute();
if (pick === undefined) return args.goBackCommand === undefined ? undefined : args.goBackCommand.execute();
repoPath = pick.repoPath;
}
const uri = args.uris !== undefined && args.uris.length !== 0 ? args.uris[0] : undefined;
const repoPath = await getRepoPathOrPrompt(
uri,
`Stash changes for which repository${GlyphChars.Ellipsis}`,
args.goBackCommand
);
if (!repoPath) return undefined;
try {
if (args.message == null) {

+ 1
- 2
src/git/git.ts Zobrazit soubor

@ -745,8 +745,7 @@ export class Git {
if (message) {
params.push('-m', message);
}
params.splice(params.length, 0, '--', ...pathspecs);
return git<string>({ cwd: repoPath }, ...params);
return git<string>({ cwd: repoPath }, ...params, '--', ...pathspecs);
}
static stash_save(repoPath: string, message?: string) {

Načítá se…
Zrušit
Uložit