mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-14 01:25:43 -05:00
Switches to use the new diffWith command
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
'use strict';
|
||||
import { commands, Range, TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
|
||||
import { commands, TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
|
||||
import { ActiveEditorCommand, Commands, getCommandUri } from './common';
|
||||
import { BuiltInCommands, GlyphChars } from '../constants';
|
||||
import { GlyphChars } from '../constants';
|
||||
import { DiffWithCommandArgs } from './diffWith';
|
||||
import { GitService, GitUri } from '../gitService';
|
||||
import { Logger } from '../logger';
|
||||
import { Messages } from '../messages';
|
||||
@@ -43,20 +44,21 @@ export class DiffWithBranchCommand extends ActiveEditorCommand {
|
||||
if (branch === undefined) return undefined;
|
||||
|
||||
try {
|
||||
const compare = await this.git.getVersionedFile(gitUri.repoPath, gitUri.fsPath, branch);
|
||||
|
||||
if (args.line !== undefined && args.line !== 0) {
|
||||
if (args.showOptions === undefined) {
|
||||
args.showOptions = {};
|
||||
}
|
||||
args.showOptions.selection = new Range(args.line, 0, args.line, 0);
|
||||
}
|
||||
|
||||
await commands.executeCommand(BuiltInCommands.Diff,
|
||||
Uri.file(compare),
|
||||
gitUri.fileUri(),
|
||||
`${path.basename(gitUri.fsPath)} (${branch}) ${GlyphChars.ArrowLeftRight} ${path.basename(gitUri.fsPath)}`,
|
||||
args.showOptions);
|
||||
const diffArgs: DiffWithCommandArgs = {
|
||||
repoPath: gitUri.repoPath,
|
||||
lhs: {
|
||||
sha: pick.branch.remote ? `remotes/${branch}` : branch,
|
||||
uri: gitUri as Uri,
|
||||
title: `${path.basename(gitUri.fsPath)} (${branch})`
|
||||
},
|
||||
rhs: {
|
||||
sha: 'HEAD',
|
||||
uri: gitUri as Uri
|
||||
},
|
||||
line: args.line,
|
||||
showOptions: args.showOptions
|
||||
};
|
||||
await commands.executeCommand(Commands.DiffWith, diffArgs);
|
||||
}
|
||||
catch (ex) {
|
||||
Logger.error(ex, 'DiffWithBranchCommand', 'getVersionedFile');
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
'use strict';
|
||||
import { commands, Range, TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
|
||||
import { commands, TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
|
||||
import { ActiveEditorCommand, Commands, getCommandUri } from './common';
|
||||
import { BuiltInCommands, GlyphChars } from '../constants';
|
||||
import { DiffWithCommandArgs } from './diffWith';
|
||||
import { GitService, GitUri } from '../gitService';
|
||||
import { Logger } from '../logger';
|
||||
import { Messages } from '../messages';
|
||||
import { CommandQuickPickItem, FileHistoryQuickPick } from '../quickPicks';
|
||||
import * as path from 'path';
|
||||
|
||||
export interface DiffWithRevisionCommandArgs {
|
||||
line?: number;
|
||||
@@ -46,20 +45,20 @@ export class DiffWithRevisionCommand extends ActiveEditorCommand {
|
||||
|
||||
if (pick instanceof CommandQuickPickItem) return pick.execute();
|
||||
|
||||
const compare = await this.git.getVersionedFile(gitUri.repoPath, gitUri.fsPath, pick.commit.sha);
|
||||
|
||||
if (args.line !== undefined && args.line !== 0) {
|
||||
if (args.showOptions === undefined) {
|
||||
args.showOptions = {};
|
||||
}
|
||||
args.showOptions.selection = new Range(args.line, 0, args.line, 0);
|
||||
}
|
||||
|
||||
await commands.executeCommand(BuiltInCommands.Diff,
|
||||
Uri.file(compare),
|
||||
gitUri.fileUri(),
|
||||
`${path.basename(gitUri.fsPath)} (${pick.commit.shortSha}) ${GlyphChars.ArrowLeftRight} ${path.basename(gitUri.fsPath)}`,
|
||||
args.showOptions);
|
||||
const diffArgs: DiffWithCommandArgs = {
|
||||
repoPath: gitUri.repoPath,
|
||||
lhs: {
|
||||
sha: pick.commit.sha,
|
||||
uri: gitUri as Uri
|
||||
},
|
||||
rhs: {
|
||||
sha: 'HEAD',
|
||||
uri: gitUri as Uri
|
||||
},
|
||||
line: args.line,
|
||||
showOptions: args.showOptions
|
||||
};
|
||||
await commands.executeCommand(Commands.DiffWith, diffArgs);
|
||||
}
|
||||
catch (ex) {
|
||||
Logger.error(ex, 'DiffWithRevisionCommand', 'getVersionedFile');
|
||||
|
||||
@@ -99,7 +99,8 @@ export class Git {
|
||||
static async getVersionedFile(repoPath: string | undefined, fileName: string, branchOrSha: string) {
|
||||
const data = await Git.show(repoPath, fileName, branchOrSha, 'binary');
|
||||
|
||||
const suffix = Git.isSha(branchOrSha) ? Git.shortenSha(branchOrSha) : branchOrSha;
|
||||
// TODO: Sanitize the filename
|
||||
const suffix = Git.isSha(branchOrSha) ? Git.shortenSha(branchOrSha) : branchOrSha.replace(/\\/g, '_').replace(/\//g, '_');
|
||||
const ext = path.extname(fileName);
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
tmp.file({ prefix: `${path.basename(fileName, ext)}-${suffix}__`, postfix: ext },
|
||||
|
||||
Reference in New Issue
Block a user