Browse Source

Adds Apply Changes command to custom view files

Adds Stash Changes command to SCM view items
main
Eric Amodio 7 years ago
parent
commit
d31eb25451
5 changed files with 1212 additions and 1137 deletions
  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 View File

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

+ 20
- 2
src/commands/stashSave.ts View File

@ -1,6 +1,7 @@
'use strict';
import { InputBoxOptions, window } from 'vscode';
import { InputBoxOptions, Uri, window } from 'vscode';
import { GitService } from '../gitService';
import { CommandContext } from '../commands';
import { Command, Commands } from './common';
import { Logger } from '../logger';
import { CommandQuickPickItem } from '../quickPicks';
@ -8,6 +9,7 @@ import { CommandQuickPickItem } from '../quickPicks';
export interface StashSaveCommandArgs {
message?: string;
unstagedOnly?: boolean;
uris?: Uri[];
goBackCommand?: CommandQuickPickItem;
}
@ -18,6 +20,22 @@ export class StashSaveCommand extends Command {
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 }) {
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();
}
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) {
Logger.error(ex, 'StashSaveCommand');

+ 17
- 4
src/git/git.ts View File

@ -177,6 +177,12 @@ export class Git {
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) {
try {
return await gitCommand({ cwd: repoPath || '' }, `config`, `--get`, key);
@ -322,11 +328,18 @@ export class Git {
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) {
params.push(message);
}

+ 1137
- 1128
src/gitService.ts
File diff suppressed because it is too large
View File


+ 6
- 0
src/views/gitExplorer.ts View File

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

Loading…
Cancel
Save