55
66'use strict' ;
77
8- import { Uri , commands , scm , Disposable , SCMResourceGroup , SCMResource , window , workspace , QuickPickItem } from 'vscode' ;
8+ import { Uri , commands , scm , Disposable , SCMResourceGroup , SCMResource , window , workspace , QuickPickItem , OutputChannel } from 'vscode' ;
99import { IRef , RefType } from './git' ;
1010import { Model , Resource } from './model' ;
1111import { log } from './util' ;
@@ -15,7 +15,30 @@ import * as path from 'path';
1515type Command = ( ...args : any [ ] ) => any ;
1616
1717function catchErrors ( fn : ( ...args ) => Promise < any > ) : ( ...args ) => void {
18- return ( ...args ) => fn . call ( this , ...args ) . catch ( err => console . log ( err ) ) ;
18+ return ( ...args ) => fn . call ( this , ...args ) . catch ( async err => {
19+ if ( err . gitErrorCode ) {
20+ let message : string ;
21+
22+ switch ( err . gitErrorCode ) {
23+ case 'DirtyWorkTree' :
24+ message = 'Please clean your repository working tree before checkout.' ;
25+ break ;
26+ default :
27+ message = ( err . stderr || err . message ) . replace ( / ^ e r r o r : / , '' ) ;
28+ break ;
29+ }
30+
31+ const outputChannel = this . outputChannel as OutputChannel ;
32+ const openOutputChannelChoice = 'Open Git Log' ;
33+ const choice = await window . showErrorMessage ( message , openOutputChannelChoice ) ;
34+
35+ if ( choice === openOutputChannelChoice ) {
36+ outputChannel . show ( ) ;
37+ }
38+ } else {
39+ console . error ( err ) ;
40+ }
41+ } ) ;
1942}
2043
2144function resolveGitURI ( uri : Uri ) : SCMResource | SCMResourceGroup | undefined {
@@ -79,7 +102,7 @@ class CommandCenter {
79102
80103 private disposables : Disposable [ ] = [ ] ;
81104
82- constructor ( private model : Model ) {
105+ constructor ( private model : Model , private outputChannel : OutputChannel ) {
83106 this . disposables . push (
84107 commands . registerCommand ( 'git.refresh' , this . refresh , this ) ,
85108 commands . registerCommand ( 'git.openChange' , this . openChange , this ) ,
@@ -229,6 +252,6 @@ class CommandCenter {
229252 }
230253}
231254
232- export function registerCommands ( model : Model ) : Disposable {
233- return new CommandCenter ( model ) ;
255+ export function registerCommands ( model : Model , outputChannel : OutputChannel ) : Disposable {
256+ return new CommandCenter ( model , outputChannel ) ;
234257}
0 commit comments