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

Commit 8ed47ae

Browse files
committed
Unset local config values when empty
1 parent f229e20 commit 8ed47ae

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

lib/controllers/git-tab-controller.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,17 @@ export default class GitTabController extends React.Component {
375375
const newUsername = this.usernameBuffer.getText();
376376
const newEmail = this.emailBuffer.getText();
377377

378-
await this.props.repository.setConfig('user.name', newUsername, options);
379-
await this.props.repository.setConfig('user.email', newEmail, options);
378+
if (newUsername.length > 0) {
379+
await this.props.repository.setConfig('user.name', newUsername, options);
380+
} else {
381+
await this.props.repository.unsetConfig('user.name');
382+
}
383+
384+
if (newEmail.length > 0) {
385+
await this.props.repository.setConfig('user.email', newEmail, options);
386+
} else {
387+
await this.props.repository.unsetConfig('user.email');
388+
}
380389
this.closeIdentityEditor();
381390
}
382391

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,21 @@ describe('GitTabController', function() {
260260
assert.isTrue(setConfig.calledWith('user.name', 'changed', {global: true}));
261261
assert.isTrue(setConfig.calledWith('user.email', '[email protected]', {global: true}));
262262
});
263+
264+
it('unsets config values when empty', async function() {
265+
const repository = await buildRepository(await cloneRepository('three-files'));
266+
const unsetConfig = sinon.stub(repository, 'unsetConfig');
267+
268+
const wrapper = mount(await buildApp(repository));
269+
270+
wrapper.find('GitTabView').prop('usernameBuffer').setText('');
271+
wrapper.find('GitTabView').prop('emailBuffer').setText('');
272+
273+
await wrapper.find('GitTabView').prop('setLocalIdentity')();
274+
275+
assert.isTrue(unsetConfig.calledWith('user.name'));
276+
assert.isTrue(unsetConfig.calledWith('user.email'));
277+
});
263278
});
264279

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

0 commit comments

Comments
 (0)