Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/git-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand All @@ -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}`)
Expand Down Expand Up @@ -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()
})
Expand Down
40 changes: 40 additions & 0 deletions spec/diff-view-model-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'")

Expand Down