提交 8dcb0d6e 编写于 作者: J Joao Moreno

🐛 improve git commit error reporting

fixes #21251
上级 cb7e5a27
...@@ -59,7 +59,7 @@ class CheckoutRemoteHeadItem extends CheckoutItem { ...@@ -59,7 +59,7 @@ class CheckoutRemoteHeadItem extends CheckoutItem {
} }
} }
const Commands: { commandId: string; method: Function; }[] = []; const Commands: { commandId: string; key: string; method: Function; }[] = [];
function command(commandId: string): Function { function command(commandId: string): Function {
return (target: any, key: string, descriptor: any) => { return (target: any, key: string, descriptor: any) => {
...@@ -67,7 +67,7 @@ function command(commandId: string): Function { ...@@ -67,7 +67,7 @@ function command(commandId: string): Function {
throw new Error('not supported'); throw new Error('not supported');
} }
Commands.push({ commandId, method: descriptor.value }); Commands.push({ commandId, key, method: descriptor.value });
}; };
} }
...@@ -86,7 +86,7 @@ export class CommandCenter { ...@@ -86,7 +86,7 @@ export class CommandCenter {
} }
this.disposables = Commands this.disposables = Commands
.map(({ commandId, method }) => commands.registerCommand(commandId, this.createCommand(commandId, method))); .map(({ commandId, key, method }) => commands.registerCommand(commandId, this.createCommand(commandId, key, method)));
} }
@command('git.refresh') @command('git.refresh')
...@@ -710,8 +710,8 @@ export class CommandCenter { ...@@ -710,8 +710,8 @@ export class CommandCenter {
this.outputChannel.show(); this.outputChannel.show();
} }
private createCommand(id: string, method: Function): (...args: any[]) => any { private createCommand(id: string, key: string, method: Function): (...args: any[]) => any {
return (...args) => { const result = (...args) => {
if (!this.model) { if (!this.model) {
window.showInformationMessage(localize('disabled', "Git is either disabled or not supported in this workspace")); window.showInformationMessage(localize('disabled', "Git is either disabled or not supported in this workspace"));
return; return;
...@@ -729,12 +729,17 @@ export class CommandCenter { ...@@ -729,12 +729,17 @@ export class CommandCenter {
message = localize('clean repo', "Please clean your repository working tree before checkout."); message = localize('clean repo', "Please clean your repository working tree before checkout.");
break; break;
default: default:
const lines = (err.stderr || err.message || String(err)) const hint = (err.stderr || err.message || String(err))
.replace(/^error: /, '') .replace(/^error: /mi, '')
.replace(/^> husky.*$/mi, '')
.split(/[\r\n]/) .split(/[\r\n]/)
.filter(line => !!line); .filter(line => !!line)
[0];
message = hint
? localize('git error details', "Git: {0}", hint)
: localize('git error', "Git error");
message = lines[0] || 'Git error';
break; break;
} }
...@@ -752,6 +757,11 @@ export class CommandCenter { ...@@ -752,6 +757,11 @@ export class CommandCenter {
} }
}); });
}; };
// patch this object, so people can call methods directly
this[key] = result;
return result;
} }
private resolveSCMResource(uri?: Uri): Resource | undefined { private resolveSCMResource(uri?: Uri): Resource | undefined {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册