mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-18 17:25:54 -05:00
Fixes a slew of issues because of the Fix for #1
This commit is contained in:
@@ -43,7 +43,7 @@ export class DiffWithPreviousCommand extends EditorCommand {
|
||||
super(Commands.DiffWithPrevious);
|
||||
}
|
||||
|
||||
execute(editor: TextEditor, edit: TextEditorEdit, uri?: Uri, sha?: string, shaUri?: Uri, compareWithSha?: string, compareWithUri?: Uri, line?: number) {
|
||||
execute(editor: TextEditor, edit: TextEditorEdit, uri?: Uri, repoPath?: string, sha?: string, shaUri?: Uri, compareWithSha?: string, compareWithUri?: Uri, line?: number) {
|
||||
line = line || editor.selection.active.line;
|
||||
if (!sha) {
|
||||
return this.git.getBlameForLine(uri.fsPath, line)
|
||||
@@ -52,9 +52,9 @@ export class DiffWithPreviousCommand extends EditorCommand {
|
||||
if (!blame) return;
|
||||
|
||||
if (UncommitedRegex.test(blame.commit.sha)) {
|
||||
return commands.executeCommand(Commands.DiffWithWorking, uri, blame.commit.previousSha, blame.commit.previousUri, line);
|
||||
return commands.executeCommand(Commands.DiffWithWorking, uri, blame.commit.repoPath, blame.commit.previousSha, blame.commit.previousUri, line);
|
||||
}
|
||||
return commands.executeCommand(Commands.DiffWithPrevious, uri, blame.commit.sha, blame.commit.uri, blame.commit.previousSha, blame.commit.previousUri, line);
|
||||
return commands.executeCommand(Commands.DiffWithPrevious, uri, blame.commit.repoPath, blame.commit.sha, blame.commit.uri, blame.commit.previousSha, blame.commit.previousUri, line);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ export class DiffWithPreviousCommand extends EditorCommand {
|
||||
return window.showInformationMessage(`Commit ${sha} has no previous commit`);
|
||||
}
|
||||
|
||||
return Promise.all([this.git.getVersionedFile(shaUri.fsPath, sha), this.git.getVersionedFile(compareWithUri.fsPath, compareWithSha)])
|
||||
return Promise.all([this.git.getVersionedFile(shaUri.fsPath, repoPath, sha), this.git.getVersionedFile(compareWithUri.fsPath, repoPath, compareWithSha)])
|
||||
.catch(ex => console.error('[GitLens.DiffWithPreviousCommand]', 'getVersionedFile', ex))
|
||||
.then(values => commands.executeCommand(BuiltInCommands.Diff, Uri.file(values[1]), Uri.file(values[0]), `${path.basename(compareWithUri.fsPath)} (${compareWithSha}) ↔ ${path.basename(shaUri.fsPath)} (${sha})`)
|
||||
.then(() => commands.executeCommand(BuiltInCommands.RevealLine, {lineNumber: line, at: 'center'})));
|
||||
@@ -74,7 +74,7 @@ export class DiffWithWorkingCommand extends EditorCommand {
|
||||
super(Commands.DiffWithWorking);
|
||||
}
|
||||
|
||||
execute(editor: TextEditor, edit: TextEditorEdit, uri?: Uri, sha?: string, shaUri?: Uri, line?: number) {
|
||||
execute(editor: TextEditor, edit: TextEditorEdit, uri?: Uri, repoPath?: string, sha?: string, shaUri?: Uri, line?: number) {
|
||||
line = line || editor.selection.active.line;
|
||||
if (!sha) {
|
||||
return this.git.getBlameForLine(uri.fsPath, line)
|
||||
@@ -83,13 +83,13 @@ export class DiffWithWorkingCommand extends EditorCommand {
|
||||
if (!blame) return;
|
||||
|
||||
if (UncommitedRegex.test(blame.commit.sha)) {
|
||||
return commands.executeCommand(Commands.DiffWithWorking, uri, blame.commit.previousSha, blame.commit.previousUri, line);
|
||||
return commands.executeCommand(Commands.DiffWithWorking, uri, blame.commit.repoPath, blame.commit.previousSha, blame.commit.previousUri, line);
|
||||
}
|
||||
return commands.executeCommand(Commands.DiffWithWorking, uri, blame.commit.sha, blame.commit.uri, line)
|
||||
return commands.executeCommand(Commands.DiffWithWorking, uri, blame.commit.repoPath, blame.commit.sha, blame.commit.uri, line)
|
||||
});
|
||||
};
|
||||
|
||||
return this.git.getVersionedFile(shaUri.fsPath, sha)
|
||||
return this.git.getVersionedFile(shaUri.fsPath, repoPath, sha)
|
||||
.catch(ex => console.error('[GitLens.DiffWithWorkingCommand]', 'getVersionedFile', ex))
|
||||
.then(compare => commands.executeCommand(BuiltInCommands.Diff, Uri.file(compare), uri, `${path.basename(shaUri.fsPath)} (${sha}) ↔ ${path.basename(uri.fsPath)} (index)`)
|
||||
.then(() => commands.executeCommand(BuiltInCommands.RevealLine, {lineNumber: line, at: 'center'})));
|
||||
|
||||
@@ -37,20 +37,24 @@ export default class Git {
|
||||
return fileName.replace(/\\/g, '/');
|
||||
}
|
||||
|
||||
static splitPath(fileName: string) {
|
||||
static splitPath(fileName: string, repoPath?: string) {
|
||||
// if (!path.isAbsolute(fileName)) {
|
||||
// console.error('[GitLens]', `Git.splitPath(${fileName}) is not an absolute path!`);
|
||||
// debugger;
|
||||
// }
|
||||
return [path.basename(fileName).replace(/\\/g, '/'), path.dirname(fileName).replace(/\\/g, '/')];
|
||||
if (repoPath) {
|
||||
return [fileName.replace(`${repoPath}/`, ''), repoPath];
|
||||
} else {
|
||||
return [path.basename(fileName).replace(/\\/g, '/'), path.dirname(fileName).replace(/\\/g, '/')];
|
||||
}
|
||||
}
|
||||
|
||||
static repoPath(cwd: string) {
|
||||
return gitCommand(cwd, 'rev-parse', '--show-toplevel').then(data => data.replace(/\r?\n|\r/g, '').replace(/\\/g, '/'));
|
||||
}
|
||||
|
||||
static blame(format: GitBlameFormat, fileName: string, sha?: string) {
|
||||
const [file, root] = Git.splitPath(Git.normalizePath(fileName));
|
||||
static blame(format: GitBlameFormat, fileName: string, repoPath?: string, sha?: string) {
|
||||
const [file, root] = Git.splitPath(Git.normalizePath(fileName), repoPath);
|
||||
|
||||
if (sha) {
|
||||
return gitCommand(root, 'blame', format, '--root', `${sha}^`, '--', file);
|
||||
@@ -58,9 +62,9 @@ export default class Git {
|
||||
return gitCommand(root, 'blame', format, '--root', '--', file);
|
||||
}
|
||||
|
||||
static getVersionedFile(fileName: string, sha: string) {
|
||||
static getVersionedFile(fileName: string, repoPath: string, sha: string) {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
Git.getVersionedFileText(fileName, sha).then(data => {
|
||||
Git.getVersionedFileText(fileName, repoPath, sha).then(data => {
|
||||
const ext = path.extname(fileName);
|
||||
tmp.file({ prefix: `${path.basename(fileName, ext)}-${sha}_`, postfix: ext }, (err, destination, fd, cleanupCallback) => {
|
||||
if (err) {
|
||||
@@ -81,8 +85,8 @@ export default class Git {
|
||||
});
|
||||
}
|
||||
|
||||
static getVersionedFileText(fileName: string, sha: string) {
|
||||
const [file, root] = Git.splitPath(Git.normalizePath(fileName));
|
||||
static getVersionedFileText(fileName: string, repoPath: string, sha: string) {
|
||||
const [file, root] = Git.splitPath(Git.normalizePath(fileName), repoPath);
|
||||
sha = sha.replace('^', '');
|
||||
|
||||
return gitCommand(root, 'show', `${sha}:./${file}`);
|
||||
|
||||
@@ -68,7 +68,11 @@ export default class GitBlameCodeLensProvider implements CodeLensProvider {
|
||||
lens.command = {
|
||||
title: `Compare with Working Tree`,
|
||||
command: Commands.DiffWithWorking,
|
||||
arguments: [Uri.file(lens.fileName), lens.commit.sha, lens.commit.uri, lens.range.start.line]
|
||||
arguments: [
|
||||
Uri.file(lens.fileName),
|
||||
lens.commit.sha,
|
||||
lens.commit.uri,
|
||||
lens.range.start.line]
|
||||
};
|
||||
return Promise.resolve(lens);
|
||||
}
|
||||
@@ -77,7 +81,14 @@ export default class GitBlameCodeLensProvider implements CodeLensProvider {
|
||||
lens.command = {
|
||||
title: `Compare with Previous (${lens.commit.previousSha})`,
|
||||
command: Commands.DiffWithPrevious,
|
||||
arguments: [Uri.file(lens.fileName), lens.commit.sha, lens.commit.uri, lens.commit.previousSha, lens.commit.previousUri, lens.range.start.line]
|
||||
arguments: [
|
||||
Uri.file(lens.fileName),
|
||||
lens.commit.repoPath,
|
||||
lens.commit.sha,
|
||||
lens.commit.uri,
|
||||
lens.commit.previousSha,
|
||||
lens.commit.previousUri,
|
||||
lens.range.start.line]
|
||||
};
|
||||
return Promise.resolve(lens);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ export default class GitBlameContentProvider implements TextDocumentContentProvi
|
||||
|
||||
//const editor = this._findEditor(Uri.file(join(data.repoPath, data.file)));
|
||||
|
||||
return this.git.getVersionedFileText(data.originalFileName || data.fileName, data.sha).then(text => {
|
||||
return this.git.getVersionedFileText(data.originalFileName || data.fileName, data.sha, data.repoPath).then(text => {
|
||||
this.update(uri);
|
||||
|
||||
// TODO: This only works on the first load -- not after since it is cached
|
||||
|
||||
@@ -37,6 +37,7 @@ export default class GitCodeActionProvider implements CodeActionProvider {
|
||||
command: Commands.DiffWithPrevious,
|
||||
arguments: [
|
||||
Uri.file(document.fileName),
|
||||
blame.commit.repoPath,
|
||||
blame.commit.sha, blame.commit.uri,
|
||||
blame.commit.previousSha, blame.commit.previousUri,
|
||||
blame.line.line
|
||||
|
||||
@@ -10,6 +10,6 @@ export default class GitContentProvider implements TextDocumentContentProvider {
|
||||
|
||||
provideTextDocumentContent(uri: Uri): string | Thenable<string> {
|
||||
const data = GitProvider.fromGitUri(uri);
|
||||
return this.git.getVersionedFileText(data.originalFileName || data.fileName, data.sha);
|
||||
return this.git.getVersionedFileText(data.originalFileName || data.fileName, data.repoPath, data.sha);
|
||||
}
|
||||
}
|
||||
@@ -292,12 +292,12 @@ export default class GitProvider extends Disposable {
|
||||
});
|
||||
}
|
||||
|
||||
getVersionedFile(fileName: string, sha: string) {
|
||||
return Git.getVersionedFile(fileName, sha);
|
||||
getVersionedFile(fileName: string, repoPath: string, sha: string) {
|
||||
return Git.getVersionedFile(fileName, repoPath, sha);
|
||||
}
|
||||
|
||||
getVersionedFileText(fileName: string, sha: string) {
|
||||
return Git.getVersionedFileText(fileName, sha);
|
||||
getVersionedFileText(fileName: string, repoPath: string, sha: string) {
|
||||
return Git.getVersionedFileText(fileName, repoPath, sha);
|
||||
}
|
||||
|
||||
static fromBlameUri(uri: Uri): IGitBlameUriData {
|
||||
@@ -336,7 +336,7 @@ export default class GitProvider extends Disposable {
|
||||
|
||||
private static _toGitUriData<T extends IGitUriData>(commit: IGitCommit, index: number, originalFileName?: string): T {
|
||||
const fileName = Git.normalizePath(path.join(commit.repoPath, commit.fileName));
|
||||
const data = { fileName: fileName, sha: commit.sha, index: index } as T;
|
||||
const data = { repoPath: commit.repoPath, fileName: fileName, sha: commit.sha, index: index } as T;
|
||||
if (originalFileName) {
|
||||
data.originalFileName = Git.normalizePath(path.join(commit.repoPath, originalFileName));
|
||||
}
|
||||
@@ -351,12 +351,13 @@ export default class GitProvider extends Disposable {
|
||||
}
|
||||
|
||||
export interface IGitUriData {
|
||||
fileName: string,
|
||||
repoPath: string;
|
||||
fileName: string;
|
||||
originalFileName?: string;
|
||||
sha: string,
|
||||
index: number
|
||||
sha: string;
|
||||
index: number;
|
||||
}
|
||||
|
||||
export interface IGitBlameUriData extends IGitUriData {
|
||||
range: Range
|
||||
range: Range;
|
||||
}
|
||||
Reference in New Issue
Block a user