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

No-op on untitled buffers #1402

Merged
merged 3 commits into from Apr 19, 2018
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: 4 additions & 2 deletions lib/controllers/root-controller.js
Expand Up @@ -498,6 +498,8 @@ export default class RootController extends React.Component {

async viewChangesForCurrentFile(stagingStatus) {
const editor = this.props.workspace.getActiveTextEditor();
if (!editor.getPath()) { return; }

const absFilePath = await fs.realpath(editor.getPath());
const repoPath = this.props.repository.getWorkingDirectoryPath();
if (repoPath === null) {
Expand Down Expand Up @@ -548,12 +550,12 @@ export default class RootController extends React.Component {

@autobind
viewUnstagedChangesForCurrentFile() {
this.viewChangesForCurrentFile('unstaged');
return this.viewChangesForCurrentFile('unstaged');
}

@autobind
viewStagedChangesForCurrentFile() {
this.viewChangesForCurrentFile('staged');
return this.viewChangesForCurrentFile('staged');
}

@autobind
Expand Down
24 changes: 24 additions & 0 deletions test/controllers/root-controller.test.js
Expand Up @@ -1052,6 +1052,18 @@ describe('RootController', function() {
assert.deepEqual(filePatchItem.goToDiffLine.args[0], [8]);
assert.equal(filePatchItem.focus.callCount, 1);
});

it('does nothing on an untitled buffer', async function() {
const workdirPath = await cloneRepository('three-files');
const repository = await buildRepository(workdirPath);
const wrapper = mount(React.cloneElement(app, {repository}));

await workspace.open();

sinon.spy(workspace, 'open');
await wrapper.instance().viewUnstagedChangesForCurrentFile();
assert.isFalse(workspace.open.called);
});
});

describe('viewStagedChangesForCurrentFile()', function() {
Expand Down Expand Up @@ -1085,6 +1097,18 @@ describe('RootController', function() {
assert.deepEqual(filePatchItem.goToDiffLine.args[0], [8]);
assert.equal(filePatchItem.focus.callCount, 1);
});

it('does nothing on an untitled buffer', async function() {
const workdirPath = await cloneRepository('three-files');
const repository = await buildRepository(workdirPath);
const wrapper = mount(React.cloneElement(app, {repository}));

await workspace.open();

sinon.spy(workspace, 'open');
await wrapper.instance().viewStagedChangesForCurrentFile();
assert.isFalse(workspace.open.called);
});
});
});
});