Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit f229e20

Browse files
committed
Action methods in GitTabController
1 parent 15d60a5 commit f229e20

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

lib/controllers/git-tab-controller.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import path from 'path';
33
import React from 'react';
44
import PropTypes from 'prop-types';
55
import {TextBuffer} from 'atom';
6-
import {CompositeDisposable} from 'event-kit';
76

87
import GitTabView from '../views/git-tab-view';
98
import 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,17 @@ export default class GitTabController extends React.Component {
371367

372368
closeIdentityEditor = () => this.setState({editingIdentity: false})
373369

374-
setUsername = () => {
375-
const newUsername = this.usernameBuffer.getText();
376-
if (newUsername !== this.props.username) {
377-
this.props.repository.setConfig('user.name', newUsername, {global: true});
378-
}
379-
}
370+
setLocalIdentity = () => this.setIdentity({});
380371

381-
setEmail = () => {
372+
setGlobalIdentity = () => this.setIdentity({global: true});
373+
374+
async setIdentity(options) {
375+
const newUsername = this.usernameBuffer.getText();
382376
const newEmail = this.emailBuffer.getText();
383-
if (newEmail !== this.props.email) {
384-
this.props.repository.setConfig('user.email', newEmail, {global: true});
385-
}
377+
378+
await this.props.repository.setConfig('user.name', newUsername, options);
379+
await this.props.repository.setConfig('user.email', newEmail, options);
380+
this.closeIdentityEditor();
386381
}
387382

388383
restoreFocus() {

test/controllers/git-tab-controller.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,36 @@ describe('GitTabController', function() {
230230
assert.strictEqual(wrapper.find('GitTabView').prop('emailBuffer'), emailBuffer);
231231
assert.strictEqual(emailBuffer.getText(), '[email protected]');
232232
});
233+
234+
it('sets repository-local identity', async function() {
235+
const repository = await buildRepository(await cloneRepository('three-files'));
236+
const setConfig = sinon.stub(repository, 'setConfig');
237+
238+
const wrapper = mount(await buildApp(repository));
239+
240+
wrapper.find('GitTabView').prop('usernameBuffer').setText('changed');
241+
wrapper.find('GitTabView').prop('emailBuffer').setText('[email protected]');
242+
243+
await wrapper.find('GitTabView').prop('setLocalIdentity')();
244+
245+
assert.isTrue(setConfig.calledWith('user.name', 'changed', {}));
246+
assert.isTrue(setConfig.calledWith('user.email', '[email protected]', {}));
247+
});
248+
249+
it('sets account-global identity', async function() {
250+
const repository = await buildRepository(await cloneRepository('three-files'));
251+
const setConfig = sinon.stub(repository, 'setConfig');
252+
253+
const wrapper = mount(await buildApp(repository));
254+
255+
wrapper.find('GitTabView').prop('usernameBuffer').setText('changed');
256+
wrapper.find('GitTabView').prop('emailBuffer').setText('[email protected]');
257+
258+
await wrapper.find('GitTabView').prop('setGlobalIdentity')();
259+
260+
assert.isTrue(setConfig.calledWith('user.name', 'changed', {global: true}));
261+
assert.isTrue(setConfig.calledWith('user.email', '[email protected]', {global: true}));
262+
});
233263
});
234264

235265
describe('abortMerge()', function() {

0 commit comments

Comments
 (0)