mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-28 09:35:41 -05:00
Adapts stash commands to new structure for views
Adds onDidChangeRepo event to GitService Refreshes stash view when repo changes
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
import { Strings } from '../system';
|
||||
import { MessageItem, window } from 'vscode';
|
||||
import { GitService, GitStashCommit } from '../gitService';
|
||||
import { Command, Commands } from './common';
|
||||
import { Command, CommandContext, Commands } from './common';
|
||||
import { GlyphChars } from '../constants';
|
||||
import { CommitQuickPickItem, StashListQuickPick } from '../quickPicks';
|
||||
import { Logger } from '../logger';
|
||||
@@ -23,59 +23,58 @@ export class StashApplyCommand extends Command {
|
||||
super(Commands.StashApply);
|
||||
}
|
||||
|
||||
async execute(args: StashApplyCommandArgs | StashCommitNode = { confirm: true, deleteAfter: false }) {
|
||||
if (!this.git.repoPath) return undefined;
|
||||
|
||||
if (args instanceof StashCommitNode) {
|
||||
try {
|
||||
const ret = await this.git.stashApply(this.git.repoPath, args.commit.stashName, false);
|
||||
args.refreshNode();
|
||||
return ret;
|
||||
} catch (ex) {
|
||||
return this._errorHandling(ex);
|
||||
}
|
||||
} else {
|
||||
protected async preExecute(context: CommandContext, args: StashApplyCommandArgs = { confirm: true, deleteAfter: false }) {
|
||||
if (context.type === 'view' && context.node instanceof StashCommitNode) {
|
||||
args = { ...args };
|
||||
if (args.stashItem === undefined || args.stashItem.stashName === undefined) {
|
||||
const stash = await this.git.getStashList(this.git.repoPath);
|
||||
if (stash === undefined) return window.showInformationMessage(`There are no stashed changes`);
|
||||
|
||||
const currentCommand = new CommandQuickPickItem({
|
||||
label: `go back ${GlyphChars.ArrowBack}`,
|
||||
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} to apply stashed changes`
|
||||
}, Commands.StashApply, [args]);
|
||||
const stash = context.node.commit;
|
||||
args.stashItem = { stashName: stash.stashName, message: stash.message };
|
||||
|
||||
const pick = await StashListQuickPick.show(this.git, stash, 'apply', args.goBackCommand, currentCommand);
|
||||
if (pick === undefined || !(pick instanceof CommitQuickPickItem)) return args.goBackCommand === undefined ? undefined : args.goBackCommand.execute();
|
||||
|
||||
args.goBackCommand = currentCommand;
|
||||
args.stashItem = pick.commit as GitStashCommit;
|
||||
}
|
||||
|
||||
try {
|
||||
if (args.confirm) {
|
||||
const message = args.stashItem.message.length > 80 ? `${args.stashItem.message.substring(0, 80)}${GlyphChars.Ellipsis}` : args.stashItem.message;
|
||||
const result = await window.showWarningMessage(`Apply stashed changes '${message}' to your working tree?`, { title: 'Yes, delete after applying' } as MessageItem, { title: 'Yes' } as MessageItem, { title: 'No', isCloseAffordance: true } as MessageItem);
|
||||
if (result === undefined || result.title === 'No') return args.goBackCommand === undefined ? undefined : args.goBackCommand.execute();
|
||||
|
||||
args.deleteAfter = result.title !== 'Yes';
|
||||
}
|
||||
|
||||
return await this.git.stashApply(this.git.repoPath, args.stashItem.stashName, args.deleteAfter);
|
||||
}
|
||||
catch (ex) {
|
||||
return this._errorHandling(ex);
|
||||
}
|
||||
return this.execute(args);
|
||||
}
|
||||
|
||||
return super.preExecute(context, args);
|
||||
}
|
||||
|
||||
private _errorHandling(ex: any) {
|
||||
Logger.error(ex, 'StashApplyCommand');
|
||||
if (ex.message.includes('Your local changes to the following files would be overwritten by merge')) {
|
||||
return window.showErrorMessage(`Unable to apply stash. Your working tree changes would be overwritten.`);
|
||||
async execute(args: StashApplyCommandArgs = { confirm: true, deleteAfter: false }) {
|
||||
if (!this.git.repoPath) return undefined;
|
||||
|
||||
args = { ...args };
|
||||
if (args.stashItem === undefined || args.stashItem.stashName === undefined) {
|
||||
const stash = await this.git.getStashList(this.git.repoPath);
|
||||
if (stash === undefined) return window.showInformationMessage(`There are no stashed changes`);
|
||||
|
||||
const currentCommand = new CommandQuickPickItem({
|
||||
label: `go back ${GlyphChars.ArrowBack}`,
|
||||
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} to apply stashed changes`
|
||||
}, Commands.StashApply, [args]);
|
||||
|
||||
const pick = await StashListQuickPick.show(this.git, stash, 'apply', args.goBackCommand, currentCommand);
|
||||
if (pick === undefined || !(pick instanceof CommitQuickPickItem)) return args.goBackCommand === undefined ? undefined : args.goBackCommand.execute();
|
||||
|
||||
args.goBackCommand = currentCommand;
|
||||
args.stashItem = pick.commit as GitStashCommit;
|
||||
}
|
||||
else {
|
||||
return window.showErrorMessage(`Unable to apply stash. See output channel for more details`);
|
||||
|
||||
try {
|
||||
if (args.confirm) {
|
||||
const message = args.stashItem.message.length > 80 ? `${args.stashItem.message.substring(0, 80)}${GlyphChars.Ellipsis}` : args.stashItem.message;
|
||||
const result = await window.showWarningMessage(`Apply stashed changes '${message}' to your working tree?`, { title: 'Yes, delete after applying' } as MessageItem, { title: 'Yes' } as MessageItem, { title: 'No', isCloseAffordance: true } as MessageItem);
|
||||
if (result === undefined || result.title === 'No') return args.goBackCommand === undefined ? undefined : args.goBackCommand.execute();
|
||||
|
||||
args.deleteAfter = result.title !== 'Yes';
|
||||
}
|
||||
|
||||
return await this.git.stashApply(this.git.repoPath, args.stashItem.stashName, args.deleteAfter);
|
||||
}
|
||||
catch (ex) {
|
||||
Logger.error(ex, 'StashApplyCommand');
|
||||
if (ex.message.includes('Your local changes to the following files would be overwritten by merge')) {
|
||||
return window.showErrorMessage(`Unable to apply stash. Your working tree changes would be overwritten.`);
|
||||
}
|
||||
else {
|
||||
return window.showErrorMessage(`Unable to apply stash. See output channel for more details`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
import { MessageItem, window } from 'vscode';
|
||||
import { Command, Commands } from './common';
|
||||
import { Command, CommandContext, Commands } from './common';
|
||||
import { GlyphChars } from '../constants';
|
||||
import { GitService } from '../gitService';
|
||||
import { Logger } from '../logger';
|
||||
@@ -20,17 +20,22 @@ export class StashDeleteCommand extends Command {
|
||||
super(Commands.StashDelete);
|
||||
}
|
||||
|
||||
async execute(args: StashDeleteCommandArgs | StashCommitNode = { confirm: true }) {
|
||||
if (!this.git.repoPath) return undefined;
|
||||
let stashCommitNode = undefined;
|
||||
if (args instanceof StashCommitNode) {
|
||||
stashCommitNode = args;
|
||||
args = {
|
||||
confirm: true,
|
||||
stashItem: args.commit
|
||||
};
|
||||
protected async preExecute(context: CommandContext, args: StashDeleteCommandArgs = { confirm: true }) {
|
||||
if (context.type === 'view' && context.node instanceof StashCommitNode) {
|
||||
args = { ...args };
|
||||
|
||||
const stash = context.node.commit;
|
||||
args.stashItem = { stashName: stash.stashName, message: stash.message };
|
||||
|
||||
return this.execute(args);
|
||||
}
|
||||
|
||||
return super.preExecute(context, args);
|
||||
}
|
||||
|
||||
async execute(args: StashDeleteCommandArgs = { confirm: true }) {
|
||||
if (!this.git.repoPath) return undefined;
|
||||
|
||||
args = { ...args };
|
||||
if (args.stashItem === undefined || args.stashItem.stashName === undefined) return undefined;
|
||||
|
||||
@@ -45,11 +50,7 @@ export class StashDeleteCommand extends Command {
|
||||
if (result === undefined || result.title !== 'Yes') return args.goBackCommand === undefined ? undefined : args.goBackCommand.execute();
|
||||
}
|
||||
|
||||
const ret = await this.git.stashDelete(this.git.repoPath, args.stashItem.stashName);
|
||||
if (stashCommitNode) {
|
||||
stashCommitNode.refreshNode();
|
||||
}
|
||||
return ret;
|
||||
return await this.git.stashDelete(this.git.repoPath, args.stashItem.stashName);
|
||||
}
|
||||
catch (ex) {
|
||||
Logger.error(ex, 'StashDeleteCommand');
|
||||
|
||||
@@ -18,7 +18,7 @@ export class StashSaveCommand extends Command {
|
||||
super(Commands.StashSave);
|
||||
}
|
||||
|
||||
async execute(args: StashSaveCommandArgs = { unstagedOnly : false }) {
|
||||
async execute(args: StashSaveCommandArgs = { unstagedOnly: false }) {
|
||||
if (!this.git.repoPath) return undefined;
|
||||
|
||||
args = { ...args };
|
||||
|
||||
Reference in New Issue
Block a user