Ver a proveniência

Adds Apply Changes command to custom view files

Adds Stash Changes command to SCM view items
main
Eric Amodio há 7 anos
ascendente
cometimento
d31eb25451
5 ficheiros alterados com 1212 adições e 1137 eliminações
  1. +32
    -3
      package.json
  2. +20
    -2
      src/commands/stashSave.ts
  3. +17
    -4
      src/git/git.ts
  4. +1137
    -1128
      src/gitService.ts
  5. +6
    -0
      src/views/gitExplorer.ts

+ 32
- 3
package.json Ver ficheiro

@ -1054,6 +1054,11 @@
"command": "gitlens.gitExplorer.openChangedFileRevisions", "command": "gitlens.gitExplorer.openChangedFileRevisions",
"title": "Open Revisions", "title": "Open Revisions",
"category": "GitLens" "category": "GitLens"
},
{
"command": "gitlens.gitExplorer.applyChanges",
"title": "Apply Changes",
"category": "GitLens"
} }
], ],
"menus": { "menus": {
@ -1245,6 +1250,10 @@
{ {
"command": "gitlens.gitExplorer.openChangedFileRevisions", "command": "gitlens.gitExplorer.openChangedFileRevisions",
"when": "false" "when": "false"
},
{
"command": "gitlens.gitExplorer.applyChanges",
"when": "false"
} }
], ],
"editor/context": [ "editor/context": [
@ -1411,6 +1420,11 @@
"command": "gitlens.closeUnchangedFiles", "command": "gitlens.closeUnchangedFiles",
"when": "gitlens:enabled", "when": "gitlens:enabled",
"group": "1_gitlens@2" "group": "1_gitlens@2"
},
{
"command": "gitlens.stashSave",
"when": "gitlens:enabled",
"group": "2_gitlens@1"
} }
], ],
"scm/resourceState/context": [ "scm/resourceState/context": [
@ -1428,6 +1442,11 @@
"command": "gitlens.showQuickFileHistory", "command": "gitlens.showQuickFileHistory",
"when": "gitlens:enabled", "when": "gitlens:enabled",
"group": "1_gitlens_1@1" "group": "1_gitlens_1@1"
},
{
"command": "gitlens.stashSave",
"when": "gitlens:enabled",
"group": "2_gitlens@1"
} }
], ],
"view/title": [ "view/title": [
@ -1519,14 +1538,19 @@
"group": "3_gitlens@2" "group": "3_gitlens@2"
}, },
{ {
"command": "gitlens.gitExplorer.applyChanges",
"when": "gitlens:enabled && view == gitlens.gitExplorer && viewItem == gitlens:commit-file",
"group": "4_gitlens@1"
},
{
"command": "gitlens.showQuickFileHistory", "command": "gitlens.showQuickFileHistory",
"when": "gitlens:isTracked && view == gitlens.gitExplorer && viewItem == gitlens:commit-file && gitlens:gitExplorer:view == repository", "when": "gitlens:isTracked && view == gitlens.gitExplorer && viewItem == gitlens:commit-file && gitlens:gitExplorer:view == repository",
"group": "4_gitlens@1"
"group": "5_gitlens@1"
}, },
{ {
"command": "gitlens.showQuickCommitFileDetails", "command": "gitlens.showQuickCommitFileDetails",
"when": "gitlens:enabled && view == gitlens.gitExplorer && viewItem == gitlens:commit-file", "when": "gitlens:enabled && view == gitlens.gitExplorer && viewItem == gitlens:commit-file",
"group": "4_gitlens@2"
"group": "5_gitlens@2"
}, },
{ {
"command": "gitlens.stashApply", "command": "gitlens.stashApply",
@ -1579,9 +1603,14 @@
"group": "3_gitlens@1" "group": "3_gitlens@1"
}, },
{ {
"command": "gitlens.gitExplorer.applyChanges",
"when": "gitlens:enabled && view == gitlens.gitExplorer && viewItem == gitlens:stash-file",
"group": "4_gitlens@1"
},
{
"command": "gitlens.showQuickFileHistory", "command": "gitlens.showQuickFileHistory",
"when": "gitlens:isTracked && view == gitlens.gitExplorer && viewItem == gitlens:stash-file", "when": "gitlens:isTracked && view == gitlens.gitExplorer && viewItem == gitlens:stash-file",
"group": "4_gitlens@1"
"group": "5_gitlens@1"
} }
] ]
}, },

+ 20
- 2
src/commands/stashSave.ts Ver ficheiro

@ -1,6 +1,7 @@
'use strict'; 'use strict';
import { InputBoxOptions, window } from 'vscode';
import { InputBoxOptions, Uri, window } from 'vscode';
import { GitService } from '../gitService'; import { GitService } from '../gitService';
import { CommandContext } from '../commands';
import { Command, Commands } from './common'; import { Command, Commands } from './common';
import { Logger } from '../logger'; import { Logger } from '../logger';
import { CommandQuickPickItem } from '../quickPicks'; import { CommandQuickPickItem } from '../quickPicks';
@ -8,6 +9,7 @@ import { CommandQuickPickItem } from '../quickPicks';
export interface StashSaveCommandArgs { export interface StashSaveCommandArgs {
message?: string; message?: string;
unstagedOnly?: boolean; unstagedOnly?: boolean;
uris?: Uri[];
goBackCommand?: CommandQuickPickItem; goBackCommand?: CommandQuickPickItem;
} }
@ -18,6 +20,22 @@ export class StashSaveCommand extends Command {
super(Commands.StashSave); super(Commands.StashSave);
} }
protected async preExecute(context: CommandContext, args: StashSaveCommandArgs = {}): Promise<any> {
if (context.type === 'scm-states') {
args = { ...args };
args.uris = context.scmResourceStates.map(s => s.resourceUri);
return this.execute(args);
}
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 = { unstagedOnly: false }) { async execute(args: StashSaveCommandArgs = { unstagedOnly: false }) {
if (!this.git.repoPath) return undefined; if (!this.git.repoPath) return undefined;
@ -35,7 +53,7 @@ export class StashSaveCommand extends Command {
if (args.message === undefined) return args.goBackCommand === undefined ? undefined : args.goBackCommand.execute(); if (args.message === undefined) return args.goBackCommand === undefined ? undefined : args.goBackCommand.execute();
} }
return await this.git.stashSave(this.git.repoPath, args.message, args.unstagedOnly);
return await this.git.stashSave(this.git.repoPath, args.message, args.uris);
} }
catch (ex) { catch (ex) {
Logger.error(ex, 'StashSaveCommand'); Logger.error(ex, 'StashSaveCommand');

+ 17
- 4
src/git/git.ts Ver ficheiro

@ -177,6 +177,12 @@ export class Git {
return gitCommand({ cwd: repoPath }, ...params); return gitCommand({ cwd: repoPath }, ...params);
} }
static checkout(repoPath: string, fileName: string, sha: string) {
const [file, root] = Git.splitPath(fileName, repoPath);
return gitCommand({ cwd: root }, `checkout`, sha, `--`, file);
}
static async config_get(key: string, repoPath?: string) { static async config_get(key: string, repoPath?: string) {
try { try {
return await gitCommand({ cwd: repoPath || '' }, `config`, `--get`, key); return await gitCommand({ cwd: repoPath || '' }, `config`, `--get`, key);
@ -322,11 +328,18 @@ export class Git {
return gitCommand({ cwd: repoPath }, ...defaultStashParams); return gitCommand({ cwd: repoPath }, ...defaultStashParams);
} }
static stash_save(repoPath: string, message?: string, unstagedOnly: boolean = false) {
const params = [`stash`, `save`, `--include-untracked`];
if (unstagedOnly) {
params.push(`--keep-index`);
static stash_push(repoPath: string, pathspecs: string[], message?: string) {
const params = [`stash`, `push`];
if (message) {
params.push(`-m`);
params.push(message);
} }
params.splice(params.length, 0, `--`, ...pathspecs);
return gitCommand({ cwd: repoPath }, ...params);
}
static stash_save(repoPath: string, message?: string) {
const params = [`stash`, `save`, `--include-untracked`];
if (message) { if (message) {
params.push(message); params.push(message);
} }

+ 1137
- 1128
src/gitService.ts
A apresentação das diferenças no ficheiro foi suprimida por ser demasiado grande
Ver ficheiro


+ 6
- 0
src/views/gitExplorer.ts Ver ficheiro

@ -43,6 +43,7 @@ export class GitExplorer implements TreeDataProvider {
commands.registerCommand('gitlens.gitExplorer.openFileRevisionInRemote', this.openFileRevisionInRemote, this); commands.registerCommand('gitlens.gitExplorer.openFileRevisionInRemote', this.openFileRevisionInRemote, this);
commands.registerCommand('gitlens.gitExplorer.openChangedFiles', this.openChangedFiles, this); commands.registerCommand('gitlens.gitExplorer.openChangedFiles', this.openChangedFiles, this);
commands.registerCommand('gitlens.gitExplorer.openChangedFileRevisions', this.openChangedFileRevisions, this); commands.registerCommand('gitlens.gitExplorer.openChangedFileRevisions', this.openChangedFileRevisions, this);
commands.registerCommand('gitlens.gitExplorer.applyChanges', this.applyChanges, this);
const fn = Functions.debounce(this.onActiveEditorChanged, 500); const fn = Functions.debounce(this.onActiveEditorChanged, 500);
context.subscriptions.push(window.onDidChangeActiveTextEditor(fn, this)); context.subscriptions.push(window.onDidChangeActiveTextEditor(fn, this));
@ -110,6 +111,11 @@ export class GitExplorer implements TreeDataProvider {
this.refresh(); this.refresh();
} }
private async applyChanges(node: CommitNode | StashNode) {
await this.git.checkoutFile(node.uri);
return this.openFile(node);
}
private openChanges(node: CommitNode | StashNode) { private openChanges(node: CommitNode | StashNode) {
const command = node.getCommand(); const command = node.getCommand();
if (command === undefined || command.arguments === undefined) return; if (command === undefined || command.arguments === undefined) return;

Carregando…
Cancelar
Guardar