mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-16 10:58:34 -05:00
Adds Apply Changes command to custom view files
Adds Stash Changes command to SCM view items
This commit is contained in:
35
package.json
35
package.json
@@ -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": [
|
||||||
@@ -1518,15 +1537,20 @@
|
|||||||
"when": "gitlens:enabled && view == gitlens.gitExplorer && viewItem == gitlens:commit-file",
|
"when": "gitlens:enabled && view == gitlens.gitExplorer && viewItem == gitlens:commit-file",
|
||||||
"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",
|
||||||
@@ -1578,10 +1602,15 @@
|
|||||||
"when": "gitlens:enabled && view == gitlens.gitExplorer && viewItem == gitlens:stash-file",
|
"when": "gitlens:enabled && view == gitlens.gitExplorer && viewItem == gitlens:stash-file",
|
||||||
"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"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -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');
|
||||||
|
|||||||
@@ -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) {
|
static stash_push(repoPath: string, pathspecs: string[], message?: string) {
|
||||||
const params = [`stash`, `save`, `--include-untracked`];
|
const params = [`stash`, `push`];
|
||||||
if (unstagedOnly) {
|
if (message) {
|
||||||
params.push(`--keep-index`);
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
2265
src/gitService.ts
2265
src/gitService.ts
File diff suppressed because it is too large
Load Diff
@@ -43,6 +43,7 @@ export class GitExplorer implements TreeDataProvider<ExplorerNode> {
|
|||||||
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<ExplorerNode> {
|
|||||||
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;
|
||||||
|
|||||||
Reference in New Issue
Block a user