@@ -6,7 +6,6 @@ import { PathExt } from '@jupyterlab/coreutils';
66import { FileBrowserModel } from '@jupyterlab/filebrowser' ;
77import { IRenderMimeRegistry } from '@jupyterlab/rendermime' ;
88import { ISettingRegistry } from '@jupyterlab/settingregistry' ;
9- import { JSONObject } from '@lumino/coreutils' ;
109import { GitExtension } from '../model' ;
1110import { sleep } from '../utils' ;
1211import { Git , ILogMessage } from '../tokens' ;
@@ -28,6 +27,9 @@ import { SuspendModal } from './SuspendModal';
2827import { Alert } from './Alert' ;
2928import { CommandIDs } from '../commandsAndMenu' ;
3029
30+ const MISSING_IDENTITY =
31+ 'Your name and email address were configured automatically' ;
32+
3133/**
3234 * Interface describing component properties.
3335 */
@@ -227,35 +229,20 @@ export class GitPanel extends React.Component<IGitPanelProps, IGitPanelState> {
227229 * @returns a promise which commits the files
228230 */
229231 commitStagedFiles = async ( message : string ) : Promise < void > => {
230- let res : boolean ;
232+ let res : Response ;
231233 if ( ! message ) {
232234 return ;
233235 }
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- }
252236 this . _log ( {
253237 severity : 'info' ,
254238 message : 'Committing changes...'
255239 } ) ;
256240 this . _suspend ( true ) ;
257241 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+ ] ) ;
259246 } catch ( err ) {
260247 this . _suspend ( false ) ;
261248 this . _log ( {
@@ -271,6 +258,10 @@ export class GitPanel extends React.Component<IGitPanelProps, IGitPanelState> {
271258 severity : 'success' ,
272259 message : 'Committed changes.'
273260 } ) ;
261+ const { output } = await res . json ( ) ;
262+ if ( output . indexOf ( MISSING_IDENTITY ) !== - 1 ) {
263+ await this . _setIdentity ( this . props . model . pathRepository ) ;
264+ }
274265 } ;
275266
276267 /**
@@ -570,37 +561,36 @@ export class GitPanel extends React.Component<IGitPanelProps, IGitPanelState> {
570561 * @param path - repository path
571562 * @returns a promise which returns a success status
572563 */
573- private async _hasIdentity ( path : string ) : Promise < boolean > {
564+ private async _setIdentity ( path : string ) : Promise < boolean > {
574565 // If the repository path changes, check the user identity
575566 if ( path !== this . _previousRepoPath ) {
576567 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 ;
603591 }
592+ this . _suspend ( false ) ;
593+ this . _previousRepoPath = path ;
604594 } catch ( error ) {
605595 throw new Error ( 'Failed to set your identity. ' + error . message ) ;
606596 }
0 commit comments