mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-25 01:25:41 -05:00
Adds 'Show Stashed Changes` command
Adds experimental 'Apply Stashed Changes' command Adds experimental 'Delete Stashed Changes' to stashed changes quick pick
This commit is contained in:
@@ -10,7 +10,8 @@ export type Commands = 'gitlens.closeUnchangedFiles' | 'gitlens.copyMessageToCli
|
||||
'gitlens.showLastQuickPick' | 'gitlens.showQuickBranchHistory' |
|
||||
'gitlens.showQuickCommitDetails' | 'gitlens.showQuickCommitFileDetails' |
|
||||
'gitlens.showQuickFileHistory' | 'gitlens.showQuickRepoHistory' |
|
||||
'gitlens.showQuickRepoStatus' |
|
||||
'gitlens.showQuickRepoStatus' | 'gitlens.showQuickStashList' |
|
||||
'gitlens.stashApply' | 'gitlens.stashDelete' | 'gitlens.stashSave' |
|
||||
'gitlens.toggleBlame' | 'gitlens.toggleCodeLens';
|
||||
export const Commands = {
|
||||
CloseUnchangedFiles: 'gitlens.closeUnchangedFiles' as Commands,
|
||||
@@ -37,6 +38,9 @@ export const Commands = {
|
||||
ShowQuickBranchHistory: 'gitlens.showQuickBranchHistory' as Commands,
|
||||
ShowQuickCurrentBranchHistory: 'gitlens.showQuickRepoHistory' as Commands,
|
||||
ShowQuickRepoStatus: 'gitlens.showQuickRepoStatus' as Commands,
|
||||
ShowQuickStashList: 'gitlens.showQuickStashList' as Commands,
|
||||
StashApply: 'gitlens.stashApply' as Commands,
|
||||
StashDelete: 'gitlens.stashDelete' as Commands,
|
||||
ToggleBlame: 'gitlens.toggleBlame' as Commands,
|
||||
ToggleCodeLens: 'gitlens.toggleCodeLens' as Commands
|
||||
};
|
||||
|
||||
@@ -46,7 +46,7 @@ export class ShowQuickCommitDetailsCommand extends ActiveEditorCachedCommand {
|
||||
}
|
||||
|
||||
try {
|
||||
if (!commit || !(commit instanceof GitLogCommit) || commit.type !== 'repo') {
|
||||
if (!commit || (commit.type !== 'repo' && commit.type !== 'stash')) {
|
||||
if (repoLog) {
|
||||
commit = repoLog.commits.get(sha);
|
||||
// If we can't find the commit, kill the repoLog
|
||||
@@ -88,7 +88,7 @@ export class ShowQuickCommitDetailsCommand extends ActiveEditorCachedCommand {
|
||||
return pick.execute();
|
||||
}
|
||||
|
||||
return commands.executeCommand(Commands.ShowQuickCommitFileDetails, pick.gitUri, pick.sha, undefined, currentCommand);
|
||||
return commands.executeCommand(Commands.ShowQuickCommitFileDetails, pick.gitUri, pick.sha, commit, currentCommand);
|
||||
}
|
||||
catch (ex) {
|
||||
Logger.error(ex, 'ShowQuickCommitDetailsCommand');
|
||||
|
||||
@@ -44,7 +44,7 @@ export class ShowQuickCommitFileDetailsCommand extends ActiveEditorCachedCommand
|
||||
}
|
||||
|
||||
try {
|
||||
if (!commit || !(commit instanceof GitLogCommit) || commit.type !== 'file') {
|
||||
if (!commit || (commit.type !== 'file' && commit.type !== 'stash')) {
|
||||
if (fileLog) {
|
||||
commit = fileLog.commits.get(sha);
|
||||
// If we can't find the commit, kill the fileLog
|
||||
|
||||
42
src/commands/showQuickStashList.ts
Normal file
42
src/commands/showQuickStashList.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
'use strict';
|
||||
import { commands, TextEditor, Uri, window } from 'vscode';
|
||||
import { ActiveEditorCachedCommand, Commands } from './common';
|
||||
import { GitService, GitUri } from '../gitService';
|
||||
import { Logger } from '../logger';
|
||||
import { CommandQuickPickItem, StashListQuickPick } from '../quickPicks';
|
||||
|
||||
export class ShowQuickStashListCommand extends ActiveEditorCachedCommand {
|
||||
|
||||
constructor(private git: GitService) {
|
||||
super(Commands.ShowQuickStashList);
|
||||
}
|
||||
|
||||
async execute(editor: TextEditor, uri?: Uri, goBackCommand?: CommandQuickPickItem) {
|
||||
if (!(uri instanceof Uri)) {
|
||||
uri = editor && editor.document && editor.document.uri;
|
||||
}
|
||||
|
||||
try {
|
||||
const repoPath = await this.git.getRepoPathFromUri(uri, this.git.repoPath);
|
||||
if (!repoPath) return window.showWarningMessage(`Unable to show stash list`);
|
||||
|
||||
const stash = await this.git.getStashList(repoPath);
|
||||
const pick = await StashListQuickPick.show(stash, undefined, goBackCommand);
|
||||
if (!pick) return undefined;
|
||||
|
||||
if (pick instanceof CommandQuickPickItem) {
|
||||
return pick.execute();
|
||||
}
|
||||
|
||||
return commands.executeCommand(Commands.ShowQuickCommitDetails, new GitUri(pick.commit.uri, pick.commit), pick.commit.sha, pick.commit,
|
||||
new CommandQuickPickItem({
|
||||
label: `go back \u21A9`,
|
||||
description: `\u00a0 \u2014 \u00a0\u00a0 to the stash list`
|
||||
}, Commands.ShowQuickStashList, [uri, goBackCommand]));
|
||||
}
|
||||
catch (ex) {
|
||||
Logger.error(ex, 'ShowQuickStashListCommand');
|
||||
return window.showErrorMessage(`Unable to show stash list. See output channel for more details`);
|
||||
}
|
||||
}
|
||||
}
|
||||
48
src/commands/stashApply.ts
Normal file
48
src/commands/stashApply.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
'use strict';
|
||||
import { MessageItem, window } from 'vscode';
|
||||
import { GitService, GitStashCommit } from '../gitService';
|
||||
import { Command, Commands } from './common';
|
||||
import { CommitQuickPickItem, StashListQuickPick } from '../quickPicks';
|
||||
import { Logger } from '../logger';
|
||||
|
||||
export class StashApplyCommand extends Command {
|
||||
|
||||
constructor(private git: GitService) {
|
||||
super(Commands.StashApply);
|
||||
}
|
||||
|
||||
async execute(stashItem: { stashName: string, message: string }, confirm: boolean = true, deleteAfter: boolean = false) {
|
||||
if (!this.git.config.insiders) return undefined;
|
||||
|
||||
if (!stashItem || !stashItem.stashName) {
|
||||
const stash = await this.git.getStashList(this.git.repoPath);
|
||||
if (!stash) return window.showInformationMessage(`There are no stashed changes`);
|
||||
|
||||
const pick = await StashListQuickPick.show(stash, 'Apply stashed changes to your working tree\u2026');
|
||||
if (!pick || !(pick instanceof CommitQuickPickItem)) return undefined;
|
||||
|
||||
stashItem = pick.commit as GitStashCommit;
|
||||
}
|
||||
|
||||
try {
|
||||
if (confirm) {
|
||||
const message = stashItem.message.length > 80 ? `${stashItem.message.substring(0, 80)}\u2026` : 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 || result.title === 'No') return undefined;
|
||||
|
||||
deleteAfter = result.title !== 'Yes';
|
||||
}
|
||||
|
||||
return await this.git.stashApply(this.git.repoPath, stashItem.stashName, 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`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
31
src/commands/stashDelete.ts
Normal file
31
src/commands/stashDelete.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
import { MessageItem, window } from 'vscode';
|
||||
import { GitService } from '../gitService';
|
||||
import { Command, Commands } from './common';
|
||||
import { Logger } from '../logger';
|
||||
|
||||
export class StashDeleteCommand extends Command {
|
||||
|
||||
constructor(private git: GitService) {
|
||||
super(Commands.StashDelete);
|
||||
}
|
||||
|
||||
async execute(stashItem: { stashName: string, message: string }, confirm: boolean = true) {
|
||||
if (!this.git.config.insiders) return undefined;
|
||||
if (!stashItem || !stashItem.stashName) return undefined;
|
||||
|
||||
try {
|
||||
if (confirm) {
|
||||
const message = stashItem.message.length > 80 ? `${stashItem.message.substring(0, 80)}\u2026` : stashItem.message;
|
||||
const result = await window.showWarningMessage(`Delete stashed changes '${message}'?`, { title: 'Yes' } as MessageItem, { title: 'No', isCloseAffordance: true } as MessageItem);
|
||||
if (!result || result.title !== 'Yes') return undefined;
|
||||
}
|
||||
|
||||
return await this.git.stashDelete(this.git.repoPath, stashItem.stashName);
|
||||
}
|
||||
catch (ex) {
|
||||
Logger.error(ex, 'StashDeleteCommand');
|
||||
return window.showErrorMessage(`Unable to delete stash. See output channel for more details`);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user