mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-05 09:45:40 -05:00
Adds openChangedFileChanges to custom view
Adds openChangedFileChangesWithWorking to custom view Removes unneeded context checks from custom view commands
This commit is contained in:
@@ -101,26 +101,18 @@ export class DiffWithCommand extends ActiveEditorCommand {
|
||||
args.showOptions.selection = new Range(args.line, 0, args.line, 0);
|
||||
}
|
||||
|
||||
let lhsPrefix = '';
|
||||
if (lhs === undefined) {
|
||||
lhsPrefix = 'deleted in ';
|
||||
}
|
||||
else if (args.rhs.sha === GitService.fakeSha) {
|
||||
lhsPrefix = 'added in ';
|
||||
}
|
||||
|
||||
let rhsPrefix = '';
|
||||
if (rhs === undefined) {
|
||||
rhsPrefix = 'deleted in ';
|
||||
}
|
||||
else if (args.lhs.sha === GitService.fakeSha) {
|
||||
else if (lhs === undefined || args.lhs.sha === GitService.fakeSha) {
|
||||
rhsPrefix = 'added in ';
|
||||
}
|
||||
|
||||
if (args.lhs.title === undefined && args.lhs.sha !== GitService.fakeSha) {
|
||||
if (args.lhs.title === undefined && lhs !== undefined && args.lhs.sha !== GitService.fakeSha) {
|
||||
args.lhs.title = (args.lhs.sha === '' || GitService.isUncommitted(args.lhs.sha))
|
||||
? `${path.basename(args.lhs.uri.fsPath)}`
|
||||
: `${path.basename(args.lhs.uri.fsPath)} (${lhsPrefix}${GitService.shortenSha(args.lhs.sha)})`;
|
||||
: `${path.basename(args.lhs.uri.fsPath)} (${GitService.shortenSha(args.lhs.sha)})`;
|
||||
}
|
||||
if (args.rhs.title === undefined && args.rhs.sha !== GitService.fakeSha) {
|
||||
args.rhs.title = (args.rhs.sha === '' || GitService.isUncommitted(args.rhs.sha))
|
||||
|
||||
@@ -358,7 +358,8 @@ export class Git {
|
||||
return await gitCommand(opts, 'show', args);
|
||||
}
|
||||
catch (ex) {
|
||||
if (/Path \'.*?\' does not exist in/.test(ex && ex.toString())) {
|
||||
const msg = ex && ex.toString();
|
||||
if (/Path \'.*?\' does not exist in/.test(msg) || /Path \'.*?\' exists on disk, but not in /.test(msg)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
import { Functions, Objects } from '../system';
|
||||
import { commands, Event, EventEmitter, ExtensionContext, TextDocumentShowOptions, TextEditor, TreeDataProvider, TreeItem, Uri, window, workspace } from 'vscode';
|
||||
import { Commands, DiffWithPreviousCommandArgs, DiffWithWorkingCommandArgs, openEditor, OpenFileInRemoteCommandArgs } from '../commands';
|
||||
import { Commands, DiffWithCommandArgs, DiffWithCommandArgsRevision, DiffWithPreviousCommandArgs, DiffWithWorkingCommandArgs, openEditor, OpenFileInRemoteCommandArgs } from '../commands';
|
||||
import { UriComparer } from '../comparers';
|
||||
import { ExtensionKey, IConfig } from '../configuration';
|
||||
import { CommandContext, setCommandContext } from '../constants';
|
||||
@@ -49,6 +49,8 @@ export class GitExplorer implements TreeDataProvider<ExplorerNode> {
|
||||
commands.registerCommand('gitlens.gitExplorer.openFileRevision', this.openFileRevision, this);
|
||||
commands.registerCommand('gitlens.gitExplorer.openFileRevisionInRemote', this.openFileRevisionInRemote, this);
|
||||
commands.registerCommand('gitlens.gitExplorer.openChangedFiles', this.openChangedFiles, this);
|
||||
commands.registerCommand('gitlens.gitExplorer.openChangedFileChanges', this.openChangedFileChanges, this);
|
||||
commands.registerCommand('gitlens.gitExplorer.openChangedFileChangesWithWorking', this.openChangedFileChangesWithWorking, this);
|
||||
commands.registerCommand('gitlens.gitExplorer.openChangedFileRevisions', this.openChangedFileRevisions, this);
|
||||
commands.registerCommand('gitlens.gitExplorer.applyChanges', this.applyChanges, this);
|
||||
|
||||
@@ -190,6 +192,29 @@ export class GitExplorer implements TreeDataProvider<ExplorerNode> {
|
||||
return openEditor(options.uri || GitService.toGitContentUri(node.uri), options.showOptions || { preserveFocus: true, preview: false });
|
||||
}
|
||||
|
||||
private async openChangedFileChanges(node: CommitNode | StashNode, options: TextDocumentShowOptions = { preserveFocus: false, preview: false }) {
|
||||
const repoPath = node.commit.repoPath;
|
||||
const uris = node.commit.fileStatuses
|
||||
.map(s => GitUri.fromFileStatus(s, repoPath));
|
||||
for (const uri of uris) {
|
||||
await this.openDiffWith(repoPath,
|
||||
{ uri: uri, sha: node.commit.previousSha !== undefined ? node.commit.previousSha : GitService.fakeSha },
|
||||
{ uri: uri, sha: node.commit.sha }, options);
|
||||
}
|
||||
}
|
||||
|
||||
private async openChangedFileChangesWithWorking(node: CommitNode | StashNode, options: TextDocumentShowOptions = { preserveFocus: false, preview: false }) {
|
||||
const repoPath = node.commit.repoPath;
|
||||
const uris = node.commit.fileStatuses
|
||||
.filter(s => s.status !== 'D')
|
||||
.map(s => GitUri.fromFileStatus(s, repoPath));
|
||||
for (const uri of uris) {
|
||||
await this.openDiffWith(repoPath,
|
||||
{ uri: uri, sha: node.commit.sha },
|
||||
{ uri: uri, sha: '' }, options);
|
||||
}
|
||||
}
|
||||
|
||||
private async openChangedFiles(node: CommitNode | StashNode, options: TextDocumentShowOptions = { preserveFocus: false, preview: false }) {
|
||||
const repoPath = node.commit.repoPath;
|
||||
const uris = node.commit.fileStatuses.filter(s => s.status !== 'D').map(s => GitUri.fromFileStatus(s, repoPath));
|
||||
@@ -207,6 +232,16 @@ export class GitExplorer implements TreeDataProvider<ExplorerNode> {
|
||||
}
|
||||
}
|
||||
|
||||
private async openDiffWith(repoPath: string, lhs: DiffWithCommandArgsRevision, rhs: DiffWithCommandArgsRevision, options: TextDocumentShowOptions = { preserveFocus: false, preview: false }) {
|
||||
const diffArgs: DiffWithCommandArgs = {
|
||||
repoPath: repoPath,
|
||||
lhs: lhs,
|
||||
rhs: rhs,
|
||||
showOptions: options
|
||||
};
|
||||
return commands.executeCommand(Commands.DiffWith, diffArgs);
|
||||
}
|
||||
|
||||
private async openFileRevisionInRemote(node: CommitNode | StashNode) {
|
||||
return commands.executeCommand(Commands.OpenFileInRemote, new GitUri(node.commit.uri, node.commit), { range: false } as OpenFileInRemoteCommandArgs);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user