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

Update amending commit message when expanded commit editor is closed #1211

Merged
merged 1 commit into from Oct 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/controllers/commit-view-controller.js
Expand Up @@ -56,7 +56,11 @@ export default class CommitViewController {
this.getCommitMessageEditors().length === 0) {
// we closed the last editor pointing to the commit message file
try {
this.regularCommitMessage = await readFile(this.getCommitMessagePath());
if (this.props.isAmending && this.props.lastCommit.isPresent()) {
this.amendingCommitMessage = await readFile(this.getCommitMessagePath());
} else {
this.regularCommitMessage = await readFile(this.getCommitMessagePath());
}
} catch (e) {
if (e.code !== 'ENOENT') {
throw e;
Expand Down
26 changes: 26 additions & 0 deletions test/controllers/commit-view-controller.test.js
Expand Up @@ -176,6 +176,32 @@ describe('CommitViewController', function() {
await assert.async.equal(controller.refs.commitView.editor.getText(), 'message in editor');
});

it('transfers the commit message contents when in amending state', async function() {
const originalMessage = 'message in box before amending';
controller.refs.commitView.editor.setText(originalMessage);

await controller.update({isAmending: true, lastCommit});
assert.equal(controller.refs.commitView.editor.getText(), lastCommit.getMessage());

commandRegistry.dispatch(atomEnvironment.views.getView(workspace), 'github:toggle-expanded-commit-message-editor');
await assert.async.equal(workspace.getActiveTextEditor().getPath(), controller.getCommitMessagePath());
const editor = workspace.getActiveTextEditor();
assert.equal(editor.getText(), lastCommit.getMessage());

const amendedMessage = lastCommit.getMessage() + 'plus some changes';
editor.setText(amendedMessage);
await editor.save();

editor.destroy();
await assert.async.equal(controller.refs.commitView.editor.getText(), amendedMessage);

await controller.update({isAmending: false});
await assert.async.equal(controller.refs.commitView.editor.getText(), originalMessage);

await controller.update({isAmending: true, lastCommit});
assert.equal(controller.refs.commitView.editor.getText(), amendedMessage);
});

it('activates editor if already opened but in background', async function() {
commandRegistry.dispatch(atomEnvironment.views.getView(workspace), 'github:toggle-expanded-commit-message-editor');
await assert.async.equal(workspace.getActiveTextEditor().getPath(), controller.getCommitMessagePath());
Expand Down