diff --git a/lib/git-service.js b/lib/git-service.js index 6d0a571710..16a0ac61a4 100644 --- a/lib/git-service.js +++ b/lib/git-service.js @@ -336,7 +336,7 @@ export default class GitService { if (selected) { newCount++ patchLines.push(`${origin}${content}`) - } else if (!stage) { + } else if ((!line.isStaged() || stage) && (line.isStaged() || !stage)) { oldCount++ newCount++ patchLines.push(` ${content}`) @@ -346,7 +346,7 @@ export default class GitService { if (selected) { oldCount++ patchLines.push(`${origin}${content}`) - } else if (stage) { + } else if ((line.isStaged() && !stage) || (!line.isStaged() && stage)) { oldCount++ newCount++ patchLines.push(` ${content}`) @@ -434,7 +434,8 @@ export default class GitService { const newPath = fileDiff.getNewPathName() return Git.Repository - .open(this.repoPath).then(repo => { + .open(this.repoPath) + .then(repo => { data.repo = repo return repo.openIndex() }) diff --git a/spec/diff-view-model-spec.js b/spec/diff-view-model-spec.js index 9e21d2d086..c912ca5fb9 100644 --- a/spec/diff-view-model-spec.js +++ b/spec/diff-view-model-spec.js @@ -507,6 +507,46 @@ describe('DiffViewModel', function () { }) describe('.stage()/.unstage()', () => { + it('stages a single line', async () => { + fs.writeFileSync(filePath, "oh the files, they are a'changin'\nCome writers and critics\nWho prophesize with your code") + + await refresh() + expectStatus('unstaged') + + let selection = new DiffSelection(viewModel, { + mode: 'line', + headPosition: [0, 0, 1], + tailPosition: [0, 0, 1] + }) + viewModel.setSelection(selection) + await viewModel.toggleSelectedLinesStageStatus() + + await refresh() + expectStatus('partial') + }) + + it('stages the entire file and unstages a single line', async () => { + fs.writeFileSync(filePath, "oh the files, they are a'changin'\nCome writers and critics\nWho prophesize with your code") + + await refresh() + expectStatus('unstaged') + + await toggleAll() + await refresh() + expectStatus('staged') + + let selection = new DiffSelection(viewModel, { + mode: 'line', + headPosition: [0, 0, 1], + tailPosition: [0, 0, 1] + }) + viewModel.setSelection(selection) + await viewModel.toggleSelectedLinesStageStatus() + + await refresh() + expectStatus('partial') + }) + it('stages/unstages the entirety of a modified file', async () => { fs.writeFileSync(filePath, "oh the files, they are a'changin'")