Skip to content

Commit

Permalink
Merge pull request #118 from chaaz/master
Browse files Browse the repository at this point in the history
Add a fix for applying 0-length destination patches
  • Loading branch information
kpdecker committed May 31, 2016
2 parents c6ac39a + d20f367 commit 4a899c0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/patch/apply.js
Expand Up @@ -81,6 +81,7 @@ export function applyPatch(source, uniDiff, options = {}) {
for (let i = 0; i < hunks.length; i++) {
let hunk = hunks[i],
toPos = hunk.offset + hunk.newStart - 1;
if (hunk.newLines == 0) { toPos++; }

for (let j = 0; j < hunk.lines.length; j++) {
let line = hunk.lines[j],
Expand Down
17 changes: 17 additions & 0 deletions test/patch/apply.js
Expand Up @@ -416,6 +416,23 @@ describe('patch/apply', function() {
+ 'line5\n');
});

it('should erase a file', function() {
expect(applyPatch(
'line1\n'
+ 'line2\n'
+ 'line3\n'
+ 'line4\n',

'--- test\theader1\n'
+ '+++ test\theader2\n'
+ '@@ -1,4 +0,0 @@\n'
+ '-line1\n'
+ '-line2\n'
+ '-line3\n'
+ '-line4\n'))
.to.equal('');
});

it('should allow custom line comparison', function() {
expect(applyPatch(
'line2\n'
Expand Down

0 comments on commit 4a899c0

Please sign in to comment.