@@ -6,7 +6,6 @@ import { PathExt } from '@jupyterlab/coreutils';
6
6
import { FileBrowserModel } from '@jupyterlab/filebrowser' ;
7
7
import { IRenderMimeRegistry } from '@jupyterlab/rendermime' ;
8
8
import { ISettingRegistry } from '@jupyterlab/settingregistry' ;
9
- import { JSONObject } from '@lumino/coreutils' ;
10
9
import { GitExtension } from '../model' ;
11
10
import { sleep } from '../utils' ;
12
11
import { Git , ILogMessage } from '../tokens' ;
@@ -28,6 +27,9 @@ import { SuspendModal } from './SuspendModal';
28
27
import { Alert } from './Alert' ;
29
28
import { CommandIDs } from '../commandsAndMenu' ;
30
29
30
+ const MISSING_IDENTITY =
31
+ 'Your name and email address were configured automatically' ;
32
+
31
33
/**
32
34
* Interface describing component properties.
33
35
*/
@@ -227,35 +229,20 @@ export class GitPanel extends React.Component<IGitPanelProps, IGitPanelState> {
227
229
* @returns a promise which commits the files
228
230
*/
229
231
commitStagedFiles = async ( message : string ) : Promise < void > => {
230
- let res : boolean ;
232
+ let res : Response ;
231
233
if ( ! message ) {
232
234
return ;
233
235
}
234
- try {
235
- res = await this . _hasIdentity ( this . props . model . pathRepository ) ;
236
- } catch ( err ) {
237
- this . _log ( {
238
- severity : 'error' ,
239
- message : 'Failed to commit changes.'
240
- } ) ;
241
- console . error ( err ) ;
242
- showErrorMessage ( 'Fail to commit' , err ) ;
243
- return ;
244
- }
245
- if ( ! res ) {
246
- this . _log ( {
247
- severity : 'error' ,
248
- message : 'Failed to commit changes.'
249
- } ) ;
250
- return ;
251
- }
252
236
this . _log ( {
253
237
severity : 'info' ,
254
238
message : 'Committing changes...'
255
239
} ) ;
256
240
this . _suspend ( true ) ;
257
241
try {
258
- await Promise . all ( [ sleep ( 1000 ) , this . props . model . commit ( message ) ] ) ;
242
+ [ , res ] = await Promise . all < any , Response > ( [
243
+ sleep ( 1000 ) ,
244
+ this . props . model . commit ( message )
245
+ ] ) ;
259
246
} catch ( err ) {
260
247
this . _suspend ( false ) ;
261
248
this . _log ( {
@@ -271,6 +258,10 @@ export class GitPanel extends React.Component<IGitPanelProps, IGitPanelState> {
271
258
severity : 'success' ,
272
259
message : 'Committed changes.'
273
260
} ) ;
261
+ const { output } = await res . json ( ) ;
262
+ if ( output . indexOf ( MISSING_IDENTITY ) !== - 1 ) {
263
+ await this . _setIdentity ( this . props . model . pathRepository ) ;
264
+ }
274
265
} ;
275
266
276
267
/**
@@ -570,37 +561,36 @@ export class GitPanel extends React.Component<IGitPanelProps, IGitPanelState> {
570
561
* @param path - repository path
571
562
* @returns a promise which returns a success status
572
563
*/
573
- private async _hasIdentity ( path : string ) : Promise < boolean > {
564
+ private async _setIdentity ( path : string ) : Promise < boolean > {
574
565
// If the repository path changes, check the user identity
575
566
if ( path !== this . _previousRepoPath ) {
576
567
try {
577
- let res = await this . props . model . config ( ) ;
578
- if ( res . ok ) {
579
- const options : JSONObject = ( await res . json ( ) ) . options ;
580
- const keys = Object . keys ( options ) ;
581
-
582
- // If the user name or e-mail is unknown, ask the user to set it
583
- if ( keys . indexOf ( 'user.name' ) < 0 || keys . indexOf ( 'user.email' ) < 0 ) {
584
- const result = await showDialog ( {
585
- title : 'Who is committing?' ,
586
- body : new GitAuthorForm ( )
587
- } ) ;
588
- if ( ! result . button . accept ) {
589
- console . log ( 'User refuses to set identity.' ) ;
590
- return false ;
591
- }
592
- const identity = result . value ;
593
- res = await this . props . model . config ( {
594
- 'user.name' : identity . name ,
595
- 'user.email' : identity . email
596
- } ) ;
597
- if ( ! res . ok ) {
598
- console . log ( await res . text ( ) ) ;
599
- return false ;
600
- }
601
- }
602
- this . _previousRepoPath = path ;
568
+ const result = await showDialog ( {
569
+ title : 'Who is committing?' ,
570
+ body : new GitAuthorForm ( )
571
+ } ) ;
572
+ if ( ! result . button . accept ) {
573
+ console . log ( 'User refuses to set identity.' ) ;
574
+ return false ;
575
+ }
576
+ const identity = result . value ;
577
+ let res = await this . props . model . config ( {
578
+ 'user.name' : identity . name ,
579
+ 'user.email' : identity . email
580
+ } ) ;
581
+ if ( ! res . ok ) {
582
+ console . log ( await res . text ( ) ) ;
583
+ return false ;
584
+ }
585
+ this . _suspend ( true ) ;
586
+ res = await this . props . model . resetAuthor ( ) ;
587
+ if ( ! res . ok ) {
588
+ this . _suspend ( false ) ;
589
+ console . log ( await res . text ( ) ) ;
590
+ return false ;
603
591
}
592
+ this . _suspend ( false ) ;
593
+ this . _previousRepoPath = path ;
604
594
} catch ( error ) {
605
595
throw new Error ( 'Failed to set your identity. ' + error . message ) ;
606
596
}
0 commit comments