From aa42ffd41314b437af434922cfe76a56d63d1961 Mon Sep 17 00:00:00 2001 From: joshaber Date: Wed, 30 Mar 2016 21:35:57 -0400 Subject: [PATCH 1/7] Let us be consistent yes. --- lib/git-service.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/git-service.js b/lib/git-service.js index 6d0a571710..61b80070ad 100644 --- a/lib/git-service.js +++ b/lib/git-service.js @@ -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() }) From 1454538694ceed5595c2a97a14a05c110e2a89af Mon Sep 17 00:00:00 2001 From: joshaber Date: Wed, 30 Mar 2016 21:36:06 -0400 Subject: [PATCH 2/7] Failing test. --- spec/diff-view-model-spec.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/spec/diff-view-model-spec.js b/spec/diff-view-model-spec.js index 9e21d2d086..6020a7c2b7 100644 --- a/spec/diff-view-model-spec.js +++ b/spec/diff-view-model-spec.js @@ -507,6 +507,28 @@ describe('DiffViewModel', function () { }) describe('.stage()/.unstage()', () => { + 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'") From 34be05a4497a3665fd42d158ceebd3ecdd2886f8 Mon Sep 17 00:00:00 2001 From: joshaber Date: Wed, 30 Mar 2016 22:00:23 -0400 Subject: [PATCH 3/7] Flip the ol' bools around. --- lib/git-service.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/git-service.js b/lib/git-service.js index 61b80070ad..96b9080eb0 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 (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 (!stage) { oldCount++ newCount++ patchLines.push(` ${content}`) From ab3d3cc6e3912f61128066ffcfa4747e5c7c9455 Mon Sep 17 00:00:00 2001 From: joshaber Date: Wed, 30 Mar 2016 22:15:09 -0400 Subject: [PATCH 4/7] Another failing test. --- spec/diff-view-model-spec.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/spec/diff-view-model-spec.js b/spec/diff-view-model-spec.js index 6020a7c2b7..55fc968fee 100644 --- a/spec/diff-view-model-spec.js +++ b/spec/diff-view-model-spec.js @@ -507,6 +507,23 @@ 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") From a0814d9d3d6095594a3a5a3bfa6c0fd709597380 Mon Sep 17 00:00:00 2001 From: joshaber Date: Wed, 30 Mar 2016 22:41:00 -0400 Subject: [PATCH 5/7] Take stagedness into account. --- lib/git-service.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/git-service.js b/lib/git-service.js index 96b9080eb0..392eb25dc4 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) { 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) { oldCount++ newCount++ patchLines.push(` ${content}`) From 06a9c38ff18d18ea210088d8bfe45a608fe4ca66 Mon Sep 17 00:00:00 2001 From: joshaber Date: Wed, 30 Mar 2016 22:41:08 -0400 Subject: [PATCH 6/7] Newlines are cool. --- spec/diff-view-model-spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/diff-view-model-spec.js b/spec/diff-view-model-spec.js index 55fc968fee..c912ca5fb9 100644 --- a/spec/diff-view-model-spec.js +++ b/spec/diff-view-model-spec.js @@ -520,6 +520,7 @@ describe('DiffViewModel', function () { }) viewModel.setSelection(selection) await viewModel.toggleSelectedLinesStageStatus() + await refresh() expectStatus('partial') }) From 7e1f9c87f417cd0407b955e54b415ad9954d3c2b Mon Sep 17 00:00:00 2001 From: joshaber Date: Wed, 30 Mar 2016 23:11:48 -0400 Subject: [PATCH 7/7] Ow my head --- lib/git-service.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/git-service.js b/lib/git-service.js index 392eb25dc4..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 (line.isStaged() && 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 (!line.isStaged() && stage) { + } else if ((line.isStaged() && !stage) || (!line.isStaged() && stage)) { oldCount++ newCount++ patchLines.push(` ${content}`)