Browse Source

Fixes #2 - Adds better error logging

main
Eric Amodio 8 years ago
parent
commit
e0cf335811
4 changed files with 20 additions and 13 deletions
  1. +11
    -3
      src/commands.ts
  2. +1
    -1
      src/extension.ts
  3. +7
    -8
      src/git.ts
  4. +1
    -1
      src/gitProvider.ts

+ 11
- 3
src/commands.ts View File

@ -47,6 +47,7 @@ export class DiffWithPreviousCommand extends EditorCommand {
line = line || editor.selection.active.line; line = line || editor.selection.active.line;
if (!sha) { if (!sha) {
return this.git.getBlameForLine(uri.fsPath, line) return this.git.getBlameForLine(uri.fsPath, line)
.catch(ex => console.error('[GitLens.DiffWithPreviousCommand]', 'getBlameForLine', ex))
.then(blame => { .then(blame => {
if (!blame) return; 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 // 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 // which for a diff could be the first difference
return Promise.all([this.git.getVersionedFile(uri.fsPath, sha), this.git.getVersionedFile(uri.fsPath, compareWithSha)]) 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(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'}))); .then(() => commands.executeCommand(BuiltInCommands.RevealLine, {lineNumber: line, at: 'center'})));
} }
@ -78,6 +80,7 @@ export class DiffWithWorkingCommand extends EditorCommand {
line = line || editor.selection.active.line; line = line || editor.selection.active.line;
if (!sha) { if (!sha) {
return this.git.getBlameForLine(uri.fsPath, line) return this.git.getBlameForLine(uri.fsPath, line)
.catch(ex => console.error('[GitLens.DiffWithWorkingCommand]', 'getBlameForLine', ex))
.then(blame => { .then(blame => {
if (!blame) return; 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 // 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 // which for a diff could be the first difference
return this.git.getVersionedFile(shaUri.fsPath, sha) 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(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'}))); .then(() => commands.executeCommand(BuiltInCommands.RevealLine, {lineNumber: line, at: 'center'})));
} }
@ -108,6 +112,7 @@ export class ShowBlameCommand extends EditorCommand {
const activeLine = editor.selection.active.line; const activeLine = editor.selection.active.line;
return this.git.getBlameForLine(editor.document.fileName, activeLine) 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)); .then(blame => this.blameController.showBlame(editor, blame && blame.commit.sha));
} }
} }
@ -130,9 +135,11 @@ export class ShowBlameHistoryCommand extends EditorCommand {
if (!uri) return; 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; const activeLine = editor.selection.active.line;
return this.git.getBlameForLine(editor.document.fileName, activeLine) 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)); .then(blame => this.blameController.toggleBlame(editor, blame && blame.commit.sha));
} }
} }

+ 1
- 1
src/extension.ts View File

@ -39,7 +39,7 @@ export function activate(context: ExtensionContext) {
context.subscriptions.push(new ShowBlameCommand(git, blameController)); context.subscriptions.push(new ShowBlameCommand(git, blameController));
context.subscriptions.push(new ToggleBlameCommand(git, blameController)); context.subscriptions.push(new ToggleBlameCommand(git, blameController));
context.subscriptions.push(new ShowBlameHistoryCommand(git)); 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 // this method is called when your extension is deactivated

+ 7
- 8
src/git.ts View File

@ -5,8 +5,13 @@ import * as tmp from 'tmp';
import {spawnPromise} from 'spawn-rx'; import {spawnPromise} from 'spawn-rx';
function gitCommand(cwd: string, ...args) { 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 { export default class Git {
@ -26,8 +31,6 @@ export default class Git {
} }
return gitCommand(repoPath, 'blame', '-fn', '--root', '--', fileName); 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) { static blamePorcelain(fileName: string, repoPath: string, sha?: string) {
@ -38,8 +41,6 @@ export default class Git {
} }
return gitCommand(repoPath, 'blame', '--porcelain', '--root', '--', fileName); 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) { static getVersionedFile(fileName: string, repoPath: string, sha: string) {
@ -70,8 +71,6 @@ export default class Git {
sha = sha.replace('^', ''); sha = sha.replace('^', '');
return gitCommand(repoPath, 'show', `${sha}:${fileName}`); return gitCommand(repoPath, 'show', `${sha}:${fileName}`);
// .then(s => { console.log(s); return s; })
// .catch(ex => console.error(ex));
} }
// static getCommitMessage(sha: string, repoPath: string) { // static getCommitMessage(sha: string, repoPath: string) {

+ 1
- 1
src/gitProvider.ts View File

@ -57,7 +57,7 @@ export default class GitProvider extends Disposable {
reset = !!reset; reset = !!reset;
if (this._blames.delete(fileName.toLowerCase())) { if (this._blames.delete(fileName.toLowerCase())) {
console.log(`GitProvider._clearBlame(${fileName}, ${reset})`);
console.log('[GitLens]', `Clear blame cache: fileName=${fileName}, reset=${reset})`);
if (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 // TODO: Killing the code lens provider is too drastic -- makes the editor jump around, need to figure out how to trigger a refresh

Loading…
Cancel
Save