mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-18 01:35:36 -05:00
Fixes #2 - Adds better error logging
This commit is contained in:
@@ -47,6 +47,7 @@ export class DiffWithPreviousCommand extends EditorCommand {
|
||||
line = line || editor.selection.active.line;
|
||||
if (!sha) {
|
||||
return this.git.getBlameForLine(uri.fsPath, line)
|
||||
.catch(ex => console.error('[GitLens.DiffWithPreviousCommand]', 'getBlameForLine', ex))
|
||||
.then(blame => {
|
||||
if (!blame) return;
|
||||
|
||||
@@ -64,6 +65,7 @@ export class DiffWithPreviousCommand extends EditorCommand {
|
||||
// TODO: Moving doesn't always seem to work -- or more accurately it seems like it moves down that number of lines from the current line
|
||||
// which for a diff could be the first difference
|
||||
return Promise.all([this.git.getVersionedFile(uri.fsPath, sha), this.git.getVersionedFile(uri.fsPath, compareWithSha)])
|
||||
.catch(ex => console.error('[GitLens.DiffWithPreviousCommand]', 'getVersionedFile', ex))
|
||||
.then(values => commands.executeCommand(BuiltInCommands.Diff, Uri.file(values[1]), Uri.file(values[0]), `${basename(compareWithUri.fsPath)} (${compareWithSha}) ↔ ${basename(shaUri.fsPath)} (${sha})`)
|
||||
.then(() => commands.executeCommand(BuiltInCommands.RevealLine, {lineNumber: line, at: 'center'})));
|
||||
}
|
||||
@@ -78,6 +80,7 @@ export class DiffWithWorkingCommand extends EditorCommand {
|
||||
line = line || editor.selection.active.line;
|
||||
if (!sha) {
|
||||
return this.git.getBlameForLine(uri.fsPath, line)
|
||||
.catch(ex => console.error('[GitLens.DiffWithWorkingCommand]', 'getBlameForLine', ex))
|
||||
.then(blame => {
|
||||
if (!blame) return;
|
||||
|
||||
@@ -91,6 +94,7 @@ export class DiffWithWorkingCommand extends EditorCommand {
|
||||
// TODO: Moving doesn't always seem to work -- or more accurately it seems like it moves down that number of lines from the current line
|
||||
// which for a diff could be the first difference
|
||||
return this.git.getVersionedFile(shaUri.fsPath, sha)
|
||||
.catch(ex => console.error('[GitLens.DiffWithWorkingCommand]', 'getVersionedFile', ex))
|
||||
.then(compare => commands.executeCommand(BuiltInCommands.Diff, Uri.file(compare), uri, `${basename(shaUri.fsPath)} (${sha}) ↔ ${basename(uri.fsPath)} (index)`)
|
||||
.then(() => commands.executeCommand(BuiltInCommands.RevealLine, {lineNumber: line, at: 'center'})));
|
||||
}
|
||||
@@ -108,6 +112,7 @@ export class ShowBlameCommand extends EditorCommand {
|
||||
|
||||
const activeLine = editor.selection.active.line;
|
||||
return this.git.getBlameForLine(editor.document.fileName, activeLine)
|
||||
.catch(ex => console.error('[GitLens.ShowBlameCommand]', 'getBlameForLine', ex))
|
||||
.then(blame => this.blameController.showBlame(editor, blame && blame.commit.sha));
|
||||
}
|
||||
}
|
||||
@@ -130,9 +135,11 @@ export class ShowBlameHistoryCommand extends EditorCommand {
|
||||
if (!uri) return;
|
||||
}
|
||||
|
||||
return this.git.getBlameLocations(uri.fsPath, range).then(locations => {
|
||||
return commands.executeCommand(BuiltInCommands.ShowReferences, uri, position, locations);
|
||||
});
|
||||
return this.git.getBlameLocations(uri.fsPath, range)
|
||||
.catch(ex => console.error('[GitLens.ShowBlameHistoryCommand]', 'getBlameLocations', ex))
|
||||
.then(locations => {
|
||||
return commands.executeCommand(BuiltInCommands.ShowReferences, uri, position, locations);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,6 +155,7 @@ export class ToggleBlameCommand extends EditorCommand {
|
||||
|
||||
const activeLine = editor.selection.active.line;
|
||||
return this.git.getBlameForLine(editor.document.fileName, activeLine)
|
||||
.catch(ex => console.error('[GitLens.ToggleBlameCommand]', 'getBlameForLine', ex))
|
||||
.then(blame => this.blameController.toggleBlame(editor, blame && blame.commit.sha));
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ export function activate(context: ExtensionContext) {
|
||||
context.subscriptions.push(new ShowBlameCommand(git, blameController));
|
||||
context.subscriptions.push(new ToggleBlameCommand(git, blameController));
|
||||
context.subscriptions.push(new ShowBlameHistoryCommand(git));
|
||||
}).catch(reason => console.warn(reason));
|
||||
}).catch(reason => console.warn('[GitLens]', reason));
|
||||
}
|
||||
|
||||
// this method is called when your extension is deactivated
|
||||
|
||||
15
src/git.ts
15
src/git.ts
@@ -5,8 +5,13 @@ import * as tmp from 'tmp';
|
||||
import {spawnPromise} from 'spawn-rx';
|
||||
|
||||
function gitCommand(cwd: string, ...args) {
|
||||
console.log('git', ...args);
|
||||
return spawnPromise('git', args, { cwd: cwd });
|
||||
console.log('[GitLens]', 'git', ...args);
|
||||
return spawnPromise('git', args, { cwd: cwd })
|
||||
// .then(s => { console.log('[GitLens]', s); return s; })
|
||||
.catch(ex => {
|
||||
console.error('[GitLens]', 'git', ...args, 'Failed:', ex);
|
||||
throw ex;
|
||||
});
|
||||
}
|
||||
|
||||
export default class Git {
|
||||
@@ -26,8 +31,6 @@ export default class Git {
|
||||
}
|
||||
|
||||
return gitCommand(repoPath, 'blame', '-fn', '--root', '--', fileName);
|
||||
// .then(s => { console.log(s); return s; })
|
||||
// .catch(ex => console.error(ex));
|
||||
}
|
||||
|
||||
static blamePorcelain(fileName: string, repoPath: string, sha?: string) {
|
||||
@@ -38,8 +41,6 @@ export default class Git {
|
||||
}
|
||||
|
||||
return gitCommand(repoPath, 'blame', '--porcelain', '--root', '--', fileName);
|
||||
// .then(s => { console.log(s); return s; })
|
||||
// .catch(ex => console.error(ex));
|
||||
}
|
||||
|
||||
static getVersionedFile(fileName: string, repoPath: string, sha: string) {
|
||||
@@ -70,8 +71,6 @@ export default class Git {
|
||||
sha = sha.replace('^', '');
|
||||
|
||||
return gitCommand(repoPath, 'show', `${sha}:${fileName}`);
|
||||
// .then(s => { console.log(s); return s; })
|
||||
// .catch(ex => console.error(ex));
|
||||
}
|
||||
|
||||
// static getCommitMessage(sha: string, repoPath: string) {
|
||||
|
||||
@@ -57,7 +57,7 @@ export default class GitProvider extends Disposable {
|
||||
reset = !!reset;
|
||||
|
||||
if (this._blames.delete(fileName.toLowerCase())) {
|
||||
console.log(`GitProvider._clearBlame(${fileName}, ${reset})`);
|
||||
console.log('[GitLens]', `Clear blame cache: fileName=${fileName}, reset=${reset})`);
|
||||
|
||||
if (reset) {
|
||||
// TODO: Killing the code lens provider is too drastic -- makes the editor jump around, need to figure out how to trigger a refresh
|
||||
|
||||
Reference in New Issue
Block a user