mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 03:54:24 +01:00
git: better error handling
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import { Uri, commands, scm, Disposable, SCMResourceGroup, SCMResource, window, workspace, QuickPickItem } from 'vscode';
|
||||
import { Uri, commands, scm, Disposable, SCMResourceGroup, SCMResource, window, workspace, QuickPickItem, OutputChannel } from 'vscode';
|
||||
import { IRef, RefType } from './git';
|
||||
import { Model, Resource } from './model';
|
||||
import { log } from './util';
|
||||
@@ -15,7 +15,30 @@ import * as path from 'path';
|
||||
type Command = (...args: any[]) => any;
|
||||
|
||||
function catchErrors(fn: (...args) => Promise<any>): (...args) => void {
|
||||
return (...args) => fn.call(this, ...args).catch(err => console.log(err));
|
||||
return (...args) => fn.call(this, ...args).catch(async err => {
|
||||
if (err.gitErrorCode) {
|
||||
let message: string;
|
||||
|
||||
switch (err.gitErrorCode) {
|
||||
case 'DirtyWorkTree':
|
||||
message = 'Please clean your repository working tree before checkout.';
|
||||
break;
|
||||
default:
|
||||
message = (err.stderr || err.message).replace(/^error: /, '');
|
||||
break;
|
||||
}
|
||||
|
||||
const outputChannel = this.outputChannel as OutputChannel;
|
||||
const openOutputChannelChoice = 'Open Git Log';
|
||||
const choice = await window.showErrorMessage(message, openOutputChannelChoice);
|
||||
|
||||
if (choice === openOutputChannelChoice) {
|
||||
outputChannel.show();
|
||||
}
|
||||
} else {
|
||||
console.error(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function resolveGitURI(uri: Uri): SCMResource | SCMResourceGroup | undefined {
|
||||
@@ -79,7 +102,7 @@ class CommandCenter {
|
||||
|
||||
private disposables: Disposable[] = [];
|
||||
|
||||
constructor(private model: Model) {
|
||||
constructor(private model: Model, private outputChannel: OutputChannel) {
|
||||
this.disposables.push(
|
||||
commands.registerCommand('git.refresh', this.refresh, this),
|
||||
commands.registerCommand('git.openChange', this.openChange, this),
|
||||
@@ -229,6 +252,6 @@ class CommandCenter {
|
||||
}
|
||||
}
|
||||
|
||||
export function registerCommands(model: Model): Disposable {
|
||||
return new CommandCenter(model);
|
||||
export function registerCommands(model: Model, outputChannel: OutputChannel): Disposable {
|
||||
return new CommandCenter(model, outputChannel);
|
||||
}
|
||||
@@ -331,7 +331,7 @@ export class Git {
|
||||
}
|
||||
|
||||
if (options.log !== false) {
|
||||
this.log(`ERROR: ${result.stderr}\n`);
|
||||
this.log(`${result.stderr}\n`);
|
||||
}
|
||||
|
||||
return Promise.reject<IExecutionResult>(new GitError({
|
||||
@@ -363,7 +363,7 @@ export class Git {
|
||||
options.env = _.assign({}, process.env, options.env || {});
|
||||
|
||||
if (options.log !== false) {
|
||||
this.log(`SPAWN: git ${args.join(' ')}\n`);
|
||||
this.log(`git ${args.join(' ')}\n`);
|
||||
}
|
||||
|
||||
return cp.spawn(this.gitPath, args, options);
|
||||
|
||||
@@ -115,7 +115,7 @@ async function init(disposables: Disposable[]): Promise<void> {
|
||||
const syncStatusBar = new SyncStatusBar(model);
|
||||
|
||||
disposables.push(
|
||||
registerCommands(model),
|
||||
registerCommands(model, outputChannel),
|
||||
scm.registerSCMProvider('git', provider),
|
||||
workspace.registerTextDocumentContentProvider('git-index', textDocumentContentProvider),
|
||||
textDocumentContentProvider,
|
||||
|
||||
@@ -70,7 +70,7 @@ export class SyncStatusBar {
|
||||
}
|
||||
|
||||
const HEAD = this.model.HEAD;
|
||||
let icon = '$(sync) ';
|
||||
let icon = '$(sync)';
|
||||
let text = '';
|
||||
|
||||
if (HEAD && HEAD.name && HEAD.commit) {
|
||||
@@ -82,7 +82,7 @@ export class SyncStatusBar {
|
||||
}
|
||||
this.raw.command = 'git.sync';
|
||||
} else {
|
||||
icon = '$(cloud-upload) ';
|
||||
icon = '$(cloud-upload)';
|
||||
this.raw.command = 'git.publish';
|
||||
}
|
||||
} else {
|
||||
@@ -90,7 +90,7 @@ export class SyncStatusBar {
|
||||
this.raw.command = '';
|
||||
}
|
||||
|
||||
this.raw.text = `${icon}${text}`;
|
||||
this.raw.text = [icon, text].join(' ').trim();
|
||||
this.raw.show();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user