diff --git a/lib/controllers/git-controller.js b/lib/controllers/git-controller.js index 3034b5cd5f..415b8fc558 100644 --- a/lib/controllers/git-controller.js +++ b/lib/controllers/git-controller.js @@ -209,7 +209,8 @@ export default class GitController extends React.Component { const repository = this.props.repository; if (!repository) { return null; } - const filePatch = await repository.getFilePatchForPath(filePath, {staged: stagingStatus === 'staged', amending}); + const staged = stagingStatus === 'staged'; + const filePatch = await repository.getFilePatchForPath(filePath, {staged, amending: staged && amending}); return new Promise(resolve => { if (filePatch) { this.setState({filePath, filePatch, stagingStatus}, () => { diff --git a/test/controllers/git-controller.test.js b/test/controllers/git-controller.test.js index ab7e28b7fb..d7fcf04881 100644 --- a/test/controllers/git-controller.test.js +++ b/test/controllers/git-controller.test.js @@ -188,6 +188,20 @@ describe('GitController', function() { assert.notEqual(originalFilePatch, wrapper.state('filePatch')); }); }); + + // https://github.com/atom/github/issues/505 + it('calls repository.getFilePatchForPath with amending: true only if staging status is staged', async () => { + const workdirPath = await cloneRepository('three-files'); + const repository = await buildRepository(workdirPath); + + app = React.cloneElement(app, {repository}); + const wrapper = shallow(app); + + sinon.stub(repository, 'getFilePatchForPath'); + await wrapper.instance().showFilePatchForPath('a.txt', 'unstaged', {amending: true}); + assert.equal(repository.getFilePatchForPath.callCount, 1); + assert.deepEqual(repository.getFilePatchForPath.args[0], ['a.txt', {staged: false, amending: false}]); + }); }); describe('diveIntoFilePatchForPath(filePath, staged, {amending, activate})', function() {