浏览代码

Adds experimental 'Stash Changes' command

Adds experimental 'Stash Changes' to stash list
Adds experimental 'Stash Unstaged Changes' to stash list
main
Eric Amodio 7 年前
父节点
当前提交
d8564c215c
共有 11 个文件被更改,包括 83 次插入8 次删除
  1. +9
    -0
      package.json
  2. +1
    -0
      src/commands.ts
  3. +1
    -0
      src/commands/common.ts
  4. +1
    -1
      src/commands/showQuickStashList.ts
  5. +1
    -1
      src/commands/stashApply.ts
  6. +32
    -0
      src/commands/stashSave.ts
  7. +2
    -1
      src/extension.ts
  8. +11
    -0
      src/git/git.ts
  9. +6
    -0
      src/gitService.ts
  10. +1
    -1
      src/quickPicks/commitDetails.ts
  11. +18
    -4
      src/quickPicks/stashList.ts

+ 9
- 0
package.json 查看文件

@ -497,6 +497,11 @@
"command": "gitlens.stashApply",
"title": "Apply Stashed Changes",
"category": "GitLens"
},
{
"command": "gitlens.stashSave",
"title": "Stash Changes",
"category": "GitLens"
}
],
"menus": {
@ -608,6 +613,10 @@
{
"command": "gitlens.stashApply",
"when": "gitlens:enabled && config.gitlens.insiders"
},
{
"command": "gitlens.stashSave",
"when": "gitlens:enabled && config.gitlens.insiders"
}
],
"explorer/context": [

+ 1
- 0
src/commands.ts 查看文件

@ -30,5 +30,6 @@ export * from './commands/showQuickRepoStatus';
export * from './commands/showQuickStashList';
export * from './commands/stashApply';
export * from './commands/stashDelete';
export * from './commands/stashSave';
export * from './commands/toggleBlame';
export * from './commands/toggleCodeLens';

+ 1
- 0
src/commands/common.ts 查看文件

@ -41,6 +41,7 @@ export const Commands = {
ShowQuickStashList: 'gitlens.showQuickStashList' as Commands,
StashApply: 'gitlens.stashApply' as Commands,
StashDelete: 'gitlens.stashDelete' as Commands,
StashSave: 'gitlens.stashSave' as Commands,
ToggleBlame: 'gitlens.toggleBlame' as Commands,
ToggleCodeLens: 'gitlens.toggleCodeLens' as Commands
};

+ 1
- 1
src/commands/showQuickStashList.ts 查看文件

@ -21,7 +21,7 @@ export class ShowQuickStashListCommand extends ActiveEditorCachedCommand {
if (!repoPath) return window.showWarningMessage(`Unable to show stashed changes`);
const stash = await this.git.getStashList(repoPath);
const pick = await StashListQuickPick.show(stash, undefined, goBackCommand);
const pick = await StashListQuickPick.show(this.git, stash, 'list', goBackCommand);
if (!pick) return undefined;
if (pick instanceof CommandQuickPickItem) {

+ 1
- 1
src/commands/stashApply.ts 查看文件

@ -18,7 +18,7 @@ export class StashApplyCommand extends Command {
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');
const pick = await StashListQuickPick.show(this.git, stash, 'apply');
if (!pick || !(pick instanceof CommitQuickPickItem)) return undefined;
stashItem = pick.commit as GitStashCommit;

+ 32
- 0
src/commands/stashSave.ts 查看文件

@ -0,0 +1,32 @@
'use strict';
import { InputBoxOptions, window } from 'vscode';
import { GitService } from '../gitService';
import { Command, Commands } from './common';
import { Logger } from '../logger';
export class StashSaveCommand extends Command {
constructor(private git: GitService) {
super(Commands.StashSave);
}
async execute(message?: string, unstagedOnly: boolean = false) {
if (!this.git.config.insiders) return undefined;
try {
if (message == null) {
message = await window.showInputBox({
prompt: `Please provide a stash message`,
placeHolder: `Stash message`
} as InputBoxOptions);
if (message === undefined) return undefined;
}
return await this.git.stashSave(this.git.repoPath, message, unstagedOnly);
}
catch (ex) {
Logger.error(ex, 'StashSaveCommand');
return window.showErrorMessage(`Unable to save stash. See output channel for more details`);
}
}
}

+ 2
- 1
src/extension.ts 查看文件

@ -14,7 +14,7 @@ import { ShowBlameCommand, ToggleBlameCommand } from './commands';
import { ShowBlameHistoryCommand, ShowFileHistoryCommand } from './commands';
import { ShowLastQuickPickCommand, ShowQuickBranchHistoryCommand, ShowQuickCurrentBranchHistoryCommand, ShowQuickCommitDetailsCommand, ShowQuickCommitFileDetailsCommand, ShowQuickFileHistoryCommand } from './commands';
import { ShowQuickRepoStatusCommand, ShowQuickStashListCommand } from './commands';
import { StashApplyCommand, StashDeleteCommand } from './commands';
import { StashApplyCommand, StashDeleteCommand, StashSaveCommand } from './commands';
import { ToggleCodeLensCommand } from './commands';
import { Keyboard } from './commands';
import { IConfig } from './configuration';
@ -120,6 +120,7 @@ export async function activate(context: ExtensionContext) {
context.subscriptions.push(new ShowQuickStashListCommand(git));
context.subscriptions.push(new StashApplyCommand(git));
context.subscriptions.push(new StashDeleteCommand(git));
context.subscriptions.push(new StashSaveCommand(git));
context.subscriptions.push(new ToggleCodeLensCommand(git));
Telemetry.trackEvent('initialized', Objects.flatten(config, 'config', true));

+ 11
- 0
src/git/git.ts 查看文件

@ -250,6 +250,17 @@ export class Git {
return gitCommand(repoPath, ...defaultStashParams);
}
static stash_save(repoPath: string, message?: string, unstagedOnly: boolean = false) {
const params = [`stash`, `save`, `--include-untracked`];
if (unstagedOnly) {
params.push(`--keep-index`);
}
if (message) {
params.push(message);
}
return gitCommand(repoPath, ...params);
}
static status(repoPath: string, porcelainVersion: number = 1): Promise<string> {
const porcelain = porcelainVersion >= 2 ? `--porcelain=v${porcelainVersion}` : '--porcelain';
return gitCommand(repoPath, 'status', porcelain, '--branch');

+ 6
- 0
src/gitService.ts 查看文件

@ -757,6 +757,12 @@ export class GitService extends Disposable {
return Git.stash_delete(repoPath, stashName);
}
stashSave(repoPath: string, message?: string, unstagedOnly: boolean = false) {
Logger.log(`stashSave('${repoPath}', ${message}, ${unstagedOnly})`);
return Git.stash_save(repoPath, message, unstagedOnly);
}
toggleCodeLens(editor: TextEditor) {
if (this.config.codeLens.visibility !== CodeLensVisibility.OnDemand ||
(!this.config.codeLens.recentChange.enabled && !this.config.codeLens.authors.enabled)) return;

+ 1
- 1
src/quickPicks/commitDetails.ts 查看文件

@ -78,7 +78,7 @@ export class CommitDetailsQuickPick {
if (stash && git.config.insiders) {
items.splice(index++, 0, new CommandQuickPickItem({
label: `$(repo-forked) Apply Stashed Changes`,
label: `$(git-pull-request) Apply Stashed Changes`,
description: `\u00a0 \u2014 \u00a0\u00a0 ${commit.message}`
}, Commands.StashApply, [commit as GitStashCommit, true, false]));

+ 18
- 4
src/quickPicks/stashList.ts 查看文件

@ -1,15 +1,27 @@
'use strict';
import { Iterables } from '../system';
import { QuickPickOptions, window } from 'vscode';
import { Keyboard } from '../commands';
import { IGitStash } from '../gitService';
import { Commands, Keyboard } from '../commands';
import { GitService, IGitStash } from '../gitService';
import { CommandQuickPickItem, CommitQuickPickItem, getQuickPickIgnoreFocusOut } from '../quickPicks';
export class StashListQuickPick {
static async show(stash: IGitStash, placeHolder?: string, goBackCommand?: CommandQuickPickItem): Promise<CommitQuickPickItem | CommandQuickPickItem | undefined> {
static async show(git: GitService, stash: IGitStash, mode: 'list' | 'apply', goBackCommand?: CommandQuickPickItem): Promise<CommitQuickPickItem | CommandQuickPickItem | undefined> {
const items = ((stash && Array.from(Iterables.map(stash.commits.values(), c => new CommitQuickPickItem(c)))) || []) as (CommitQuickPickItem | CommandQuickPickItem)[];
if (mode === 'list' && git.config.insiders) {
items.splice(0, 0, new CommandQuickPickItem({
label: `$(repo-push) Stash Unstaged Changes`,
description: `\u00a0 \u2014 \u00a0\u00a0 stashes only unstaged changes`
}, Commands.StashSave, [undefined, true]));
items.splice(0, 0, new CommandQuickPickItem({
label: `$(repo-push) Stash Changes`,
description: `\u00a0 \u2014 \u00a0\u00a0 stashes all changes`
}, Commands.StashSave));
}
if (goBackCommand) {
items.splice(0, 0, goBackCommand);
}
@ -18,7 +30,9 @@ export class StashListQuickPick {
const pick = await window.showQuickPick(items, {
matchOnDescription: true,
placeHolder: placeHolder || `stashed changes \u2014 search by message, filename, or sha`,
placeHolder: mode === 'apply'
? `Apply stashed changes to your working tree\u2026`
: `stashed changes \u2014 search by message, filename, or sha`,
ignoreFocusOut: getQuickPickIgnoreFocusOut()
// onDidSelectItem: (item: QuickPickItem) => {
// scope.setKeyCommand('right', item);

正在加载...
取消
保存