@@ -3,7 +3,6 @@ import path from 'path';
33import React from 'react' ;
44import PropTypes from 'prop-types' ;
55import { TextBuffer } from 'atom' ;
6- import { CompositeDisposable } from 'event-kit' ;
76
87import GitTabView from '../views/git-tab-view' ;
98import UserStore from '../models/user-store' ;
@@ -87,11 +86,6 @@ export default class GitTabController extends React.Component {
8786 login : this . props . loginModel ,
8887 config : this . props . config ,
8988 } ) ;
90-
91- this . subs = new CompositeDisposable (
92- this . usernameBuffer . onDidStopChanging ( this . setUsername ) ,
93- this . emailBuffer . onDidStopChanging ( this . setEmail ) ,
94- ) ;
9589 }
9690
9791 static getDerivedStateFromProps ( props , state ) {
@@ -142,6 +136,8 @@ export default class GitTabController extends React.Component {
142136
143137 toggleIdentityEditor = { this . toggleIdentityEditor }
144138 closeIdentityEditor = { this . closeIdentityEditor }
139+ setLocalIdentity = { this . setLocalIdentity }
140+ setGlobalIdentity = { this . setGlobalIdentity }
145141 openInitializeDialog = { this . props . openInitializeDialog }
146142 openFiles = { this . props . openFiles }
147143 discardWorkDirChangesForPaths = { this . props . discardWorkDirChangesForPaths }
@@ -371,18 +367,26 @@ export default class GitTabController extends React.Component {
371367
372368 closeIdentityEditor = ( ) => this . setState ( { editingIdentity : false } )
373369
374- setUsername = ( ) => {
370+ setLocalIdentity = ( ) => this . setIdentity ( { } ) ;
371+
372+ setGlobalIdentity = ( ) => this . setIdentity ( { global : true } ) ;
373+
374+ async setIdentity ( options ) {
375375 const newUsername = this . usernameBuffer . getText ( ) ;
376- if ( newUsername !== this . props . username ) {
377- this . props . repository . setConfig ( 'user.name' , newUsername , { global : true } ) ;
376+ const newEmail = this . emailBuffer . getText ( ) ;
377+
378+ if ( newUsername . length > 0 || options . global ) {
379+ await this . props . repository . setConfig ( 'user.name' , newUsername , options ) ;
380+ } else {
381+ await this . props . repository . unsetConfig ( 'user.name' ) ;
378382 }
379- }
380383
381- setEmail = ( ) => {
382- const newEmail = this . emailBuffer . getText ( ) ;
383- if ( newEmail !== this . props . email ) {
384- this . props . repository . setConfig ( 'user.email' , newEmail , { global : true } ) ;
384+ if ( newEmail . length > 0 || options . global ) {
385+ await this . props . repository . setConfig ( 'user.email' , newEmail , options ) ;
386+ } else {
387+ await this . props . repository . unsetConfig ( 'user.email' ) ;
385388 }
389+ this . closeIdentityEditor ( ) ;
386390 }
387391
388392 restoreFocus ( ) {
0 commit comments