what-the-diff
Advanced tools
Comparing version 0.1.1 to 0.2.0
@@ -145,26 +145,21 @@ /* | ||
peg$c0 = function(diffs) { return diffs }, | ||
peg$c1 = function(header, file_modes, patch) { return postProcessDiff(header, file_modes, patch) }, | ||
peg$c2 = function(path, patch) { | ||
patch.status = 'unmerged' | ||
patch.filePath = path | ||
return patch | ||
}, | ||
peg$c3 = "diff --cc ", | ||
peg$c4 = peg$literalExpectation("diff --cc ", false), | ||
peg$c5 = function(path) { return path }, | ||
peg$c6 = "* Unmerged path ", | ||
peg$c7 = peg$literalExpectation("* Unmerged path ", false), | ||
peg$c8 = function(path) { | ||
return { | ||
filePath: path, | ||
status: 'unmerged' | ||
} | ||
}, | ||
peg$c9 = function(header, hunks) { return {hunks} }, | ||
peg$c10 = "--- ", | ||
peg$c11 = peg$literalExpectation("--- ", false), | ||
peg$c12 = "+++ ", | ||
peg$c13 = peg$literalExpectation("+++ ", false), | ||
peg$c14 = function(old_file_name, new_file_name) { return {old_file_name, new_file_name} }, | ||
peg$c15 = function(header, lines) { | ||
peg$c1 = function(header, file_modes) { return postProcessDiff(header, file_modes, undefined, true) }, | ||
peg$c2 = "Binary files ", | ||
peg$c3 = peg$literalExpectation("Binary files ", false), | ||
peg$c4 = function(header, file_modes, patch) { return postProcessDiff(header, file_modes, patch) }, | ||
peg$c5 = function(path) { return postProcessMergeConflictDiff(path, undefined, true) }, | ||
peg$c6 = function(path, patch) { return postProcessMergeConflictDiff(path, patch) }, | ||
peg$c7 = "diff --cc ", | ||
peg$c8 = peg$literalExpectation("diff --cc ", false), | ||
peg$c9 = function(path) { return path }, | ||
peg$c10 = "* Unmerged path ", | ||
peg$c11 = peg$literalExpectation("* Unmerged path ", false), | ||
peg$c12 = function(path) { return postProcessMergeConflictDiff(path) }, | ||
peg$c13 = function(header, hunks) { return {hunks} }, | ||
peg$c14 = "--- ", | ||
peg$c15 = peg$literalExpectation("--- ", false), | ||
peg$c16 = "+++ ", | ||
peg$c17 = peg$literalExpectation("+++ ", false), | ||
peg$c18 = function(old_file_name, new_file_name) { return {old_file_name, new_file_name} }, | ||
peg$c19 = function(header, lines) { | ||
return Object.assign({}, header, { | ||
@@ -174,11 +169,11 @@ lines: lines | ||
}, | ||
peg$c16 = "@@@ -", | ||
peg$c17 = peg$literalExpectation("@@@ -", false), | ||
peg$c18 = " -", | ||
peg$c19 = peg$literalExpectation(" -", false), | ||
peg$c20 = " +", | ||
peg$c21 = peg$literalExpectation(" +", false), | ||
peg$c22 = " @@@", | ||
peg$c23 = peg$literalExpectation(" @@@", false), | ||
peg$c24 = function(our_range, base_range, their_range, context) { | ||
peg$c20 = "@@@ -", | ||
peg$c21 = peg$literalExpectation("@@@ -", false), | ||
peg$c22 = " -", | ||
peg$c23 = peg$literalExpectation(" -", false), | ||
peg$c24 = " +", | ||
peg$c25 = peg$literalExpectation(" +", false), | ||
peg$c26 = " @@@", | ||
peg$c27 = peg$literalExpectation(" @@@", false), | ||
peg$c28 = function(our_range, base_range, their_range, context) { | ||
return { | ||
@@ -193,7 +188,7 @@ ourStartLine: our_range.start, | ||
}, | ||
peg$c25 = "@@ -", | ||
peg$c26 = peg$literalExpectation("@@ -", false), | ||
peg$c27 = " @@", | ||
peg$c28 = peg$literalExpectation(" @@", false), | ||
peg$c29 = function(old_range, new_range, context) { | ||
peg$c29 = "@@ -", | ||
peg$c30 = peg$literalExpectation("@@ -", false), | ||
peg$c31 = " @@", | ||
peg$c32 = peg$literalExpectation(" @@", false), | ||
peg$c33 = function(old_range, new_range, context) { | ||
return { | ||
@@ -206,52 +201,52 @@ oldStartLine: old_range.start, | ||
}, | ||
peg$c30 = ",", | ||
peg$c31 = peg$literalExpectation(",", false), | ||
peg$c32 = function(start, count) { return {start, count} }, | ||
peg$c33 = function(start) { return {start, count: 1} }, | ||
peg$c34 = "+", | ||
peg$c35 = peg$literalExpectation("+", false), | ||
peg$c36 = "-", | ||
peg$c37 = peg$literalExpectation("-", false), | ||
peg$c38 = " ", | ||
peg$c39 = peg$literalExpectation(" ", false), | ||
peg$c40 = "\\", | ||
peg$c41 = peg$literalExpectation("\\", false), | ||
peg$c42 = function(chars) { return chars.join('') }, | ||
peg$c43 = "diff ", | ||
peg$c44 = peg$literalExpectation("diff ", false), | ||
peg$c45 = function(options, file_name) { return {file_name} }, | ||
peg$c46 = function(str) { return str.substr(str.length/2 + 1) }, | ||
peg$c47 = function(explicit_file_modes, index_file_modes) { return explicit_file_modes || index_file_modes }, | ||
peg$c48 = "new", | ||
peg$c49 = peg$literalExpectation("new", false), | ||
peg$c50 = "deleted", | ||
peg$c51 = peg$literalExpectation("deleted", false), | ||
peg$c52 = " file mode ", | ||
peg$c53 = peg$literalExpectation(" file mode ", false), | ||
peg$c54 = function(type, file_mode) { | ||
peg$c34 = ",", | ||
peg$c35 = peg$literalExpectation(",", false), | ||
peg$c36 = function(start, count) { return {start, count} }, | ||
peg$c37 = function(start) { return {start, count: 1} }, | ||
peg$c38 = "+", | ||
peg$c39 = peg$literalExpectation("+", false), | ||
peg$c40 = "-", | ||
peg$c41 = peg$literalExpectation("-", false), | ||
peg$c42 = " ", | ||
peg$c43 = peg$literalExpectation(" ", false), | ||
peg$c44 = "\\", | ||
peg$c45 = peg$literalExpectation("\\", false), | ||
peg$c46 = function(chars) { return chars.join('') }, | ||
peg$c47 = "diff ", | ||
peg$c48 = peg$literalExpectation("diff ", false), | ||
peg$c49 = function(options, file_name) { return {file_name} }, | ||
peg$c50 = function(str) { return str.substr(str.length/2 + 1) }, | ||
peg$c51 = function(explicit_file_modes, index_file_modes) { return explicit_file_modes || index_file_modes }, | ||
peg$c52 = "new", | ||
peg$c53 = peg$literalExpectation("new", false), | ||
peg$c54 = "deleted", | ||
peg$c55 = peg$literalExpectation("deleted", false), | ||
peg$c56 = " file mode ", | ||
peg$c57 = peg$literalExpectation(" file mode ", false), | ||
peg$c58 = function(type, file_mode) { | ||
if (type === 'new') return {old_mode: null, new_mode: file_mode} | ||
else return {old_mode: file_mode, new_mode: null} | ||
}, | ||
peg$c55 = "old mode ", | ||
peg$c56 = peg$literalExpectation("old mode ", false), | ||
peg$c57 = "new mode ", | ||
peg$c58 = peg$literalExpectation("new mode ", false), | ||
peg$c59 = function(old_mode, new_mode) { return {old_mode, new_mode} }, | ||
peg$c60 = "index ", | ||
peg$c61 = peg$literalExpectation("index ", false), | ||
peg$c62 = function(file_mode) { return {old_mode: file_mode, new_mode: file_mode} }, | ||
peg$c63 = /^[ \t]/, | ||
peg$c64 = peg$classExpectation([" ", "\t"], false, false), | ||
peg$c65 = "\n", | ||
peg$c66 = peg$literalExpectation("\n", false), | ||
peg$c67 = "\r\n", | ||
peg$c68 = peg$literalExpectation("\r\n", false), | ||
peg$c69 = peg$anyExpectation(), | ||
peg$c70 = /^[^\r\n]/, | ||
peg$c71 = peg$classExpectation(["\r", "\n"], true, false), | ||
peg$c72 = /^[^ \t\r\n]/, | ||
peg$c73 = peg$classExpectation([" ", "\t", "\r", "\n"], true, false), | ||
peg$c74 = /^[0-9]/, | ||
peg$c75 = peg$classExpectation([["0", "9"]], false, false), | ||
peg$c76 = function(chars) { return parseInt(chars.join(''), 10) }, | ||
peg$c59 = "old mode ", | ||
peg$c60 = peg$literalExpectation("old mode ", false), | ||
peg$c61 = "new mode ", | ||
peg$c62 = peg$literalExpectation("new mode ", false), | ||
peg$c63 = function(old_mode, new_mode) { return {old_mode, new_mode} }, | ||
peg$c64 = "index ", | ||
peg$c65 = peg$literalExpectation("index ", false), | ||
peg$c66 = function(file_mode) { return {old_mode: file_mode, new_mode: file_mode} }, | ||
peg$c67 = /^[ \t]/, | ||
peg$c68 = peg$classExpectation([" ", "\t"], false, false), | ||
peg$c69 = "\n", | ||
peg$c70 = peg$literalExpectation("\n", false), | ||
peg$c71 = "\r\n", | ||
peg$c72 = peg$literalExpectation("\r\n", false), | ||
peg$c73 = peg$anyExpectation(), | ||
peg$c74 = /^[^\r\n]/, | ||
peg$c75 = peg$classExpectation(["\r", "\n"], true, false), | ||
peg$c76 = /^[^ \t\r\n]/, | ||
peg$c77 = peg$classExpectation([" ", "\t", "\r", "\n"], true, false), | ||
peg$c78 = /^[0-9]/, | ||
peg$c79 = peg$classExpectation([["0", "9"]], false, false), | ||
peg$c80 = function(chars) { return parseInt(chars.join(''), 10) }, | ||
@@ -399,3 +394,3 @@ peg$currPos = 0, | ||
var key = peg$currPos * 27 + 0, | ||
var key = peg$currPos * 30 + 0, | ||
cached = peg$resultsCache[key]; | ||
@@ -430,3 +425,3 @@ | ||
var key = peg$currPos * 27 + 1, | ||
var key = peg$currPos * 30 + 1, | ||
cached = peg$resultsCache[key]; | ||
@@ -440,7 +435,13 @@ | ||
s0 = peg$parsemerge_conflict_diff(); | ||
s0 = peg$parsebinary_merge_conflict_diff(); | ||
if (s0 === peg$FAILED) { | ||
s0 = peg$parseunmerged_path(); | ||
s0 = peg$parsemerge_conflict_diff(); | ||
if (s0 === peg$FAILED) { | ||
s0 = peg$parseregular_diff(); | ||
s0 = peg$parseunmerged_path(); | ||
if (s0 === peg$FAILED) { | ||
s0 = peg$parsebinary_diff(); | ||
if (s0 === peg$FAILED) { | ||
s0 = peg$parseregular_diff(); | ||
} | ||
} | ||
} | ||
@@ -454,6 +455,94 @@ } | ||
function peg$parsebinary_diff() { | ||
var s0, s1, s2, s3; | ||
var key = peg$currPos * 30 + 2, | ||
cached = peg$resultsCache[key]; | ||
if (cached) { | ||
peg$currPos = cached.nextPos; | ||
return cached.result; | ||
} | ||
s0 = peg$currPos; | ||
s1 = peg$parsediff_header_line(); | ||
if (s1 !== peg$FAILED) { | ||
s2 = peg$parsefile_mode_section(); | ||
if (s2 === peg$FAILED) { | ||
s2 = null; | ||
} | ||
if (s2 !== peg$FAILED) { | ||
s3 = peg$parsebinary_declaration(); | ||
if (s3 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s1 = peg$c1(s1, s2); | ||
s0 = s1; | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; | ||
return s0; | ||
} | ||
function peg$parsebinary_declaration() { | ||
var s0, s1, s2, s3; | ||
var key = peg$currPos * 30 + 3, | ||
cached = peg$resultsCache[key]; | ||
if (cached) { | ||
peg$currPos = cached.nextPos; | ||
return cached.result; | ||
} | ||
s0 = peg$currPos; | ||
if (input.substr(peg$currPos, 13) === peg$c2) { | ||
s1 = peg$c2; | ||
peg$currPos += 13; | ||
} else { | ||
s1 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c3); } | ||
} | ||
if (s1 !== peg$FAILED) { | ||
s2 = peg$parseTEXT(); | ||
if (s2 !== peg$FAILED) { | ||
s3 = peg$parseNL(); | ||
if (s3 !== peg$FAILED) { | ||
s1 = [s1, s2, s3]; | ||
s0 = s1; | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; | ||
return s0; | ||
} | ||
function peg$parseregular_diff() { | ||
var s0, s1, s2, s3; | ||
var key = peg$currPos * 27 + 2, | ||
var key = peg$currPos * 30 + 4, | ||
cached = peg$resultsCache[key]; | ||
@@ -481,3 +570,3 @@ | ||
peg$savedPos = s0; | ||
s1 = peg$c1(s1, s2, s3); | ||
s1 = peg$c4(s1, s2, s3); | ||
s0 = s1; | ||
@@ -502,6 +591,46 @@ } else { | ||
function peg$parsebinary_merge_conflict_diff() { | ||
var s0, s1, s2, s3; | ||
var key = peg$currPos * 30 + 5, | ||
cached = peg$resultsCache[key]; | ||
if (cached) { | ||
peg$currPos = cached.nextPos; | ||
return cached.result; | ||
} | ||
s0 = peg$currPos; | ||
s1 = peg$parsemerge_conflict_header_line(); | ||
if (s1 !== peg$FAILED) { | ||
s2 = peg$parseindex_line(); | ||
if (s2 !== peg$FAILED) { | ||
s3 = peg$parsebinary_declaration(); | ||
if (s3 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s1 = peg$c5(s1); | ||
s0 = s1; | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; | ||
return s0; | ||
} | ||
function peg$parsemerge_conflict_diff() { | ||
var s0, s1, s2, s3; | ||
var key = peg$currPos * 27 + 3, | ||
var key = peg$currPos * 30 + 6, | ||
cached = peg$resultsCache[key]; | ||
@@ -526,3 +655,3 @@ | ||
peg$savedPos = s0; | ||
s1 = peg$c2(s1, s3); | ||
s1 = peg$c6(s1, s3); | ||
s0 = s1; | ||
@@ -550,3 +679,3 @@ } else { | ||
var key = peg$currPos * 27 + 4, | ||
var key = peg$currPos * 30 + 7, | ||
cached = peg$resultsCache[key]; | ||
@@ -561,8 +690,8 @@ | ||
s0 = peg$currPos; | ||
if (input.substr(peg$currPos, 10) === peg$c3) { | ||
s1 = peg$c3; | ||
if (input.substr(peg$currPos, 10) === peg$c7) { | ||
s1 = peg$c7; | ||
peg$currPos += 10; | ||
} else { | ||
s1 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c4); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c8); } | ||
} | ||
@@ -575,3 +704,3 @@ if (s1 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s1 = peg$c5(s2); | ||
s1 = peg$c9(s2); | ||
s0 = s1; | ||
@@ -599,3 +728,3 @@ } else { | ||
var key = peg$currPos * 27 + 5, | ||
var key = peg$currPos * 30 + 8, | ||
cached = peg$resultsCache[key]; | ||
@@ -610,8 +739,8 @@ | ||
s0 = peg$currPos; | ||
if (input.substr(peg$currPos, 16) === peg$c6) { | ||
s1 = peg$c6; | ||
if (input.substr(peg$currPos, 16) === peg$c10) { | ||
s1 = peg$c10; | ||
peg$currPos += 16; | ||
} else { | ||
s1 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c7); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c11); } | ||
} | ||
@@ -624,3 +753,3 @@ if (s1 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s1 = peg$c8(s2); | ||
s1 = peg$c12(s2); | ||
s0 = s1; | ||
@@ -648,3 +777,3 @@ } else { | ||
var key = peg$currPos * 27 + 6, | ||
var key = peg$currPos * 30 + 9, | ||
cached = peg$resultsCache[key]; | ||
@@ -673,3 +802,3 @@ | ||
peg$savedPos = s0; | ||
s1 = peg$c9(s1, s2); | ||
s1 = peg$c13(s1, s2); | ||
s0 = s1; | ||
@@ -693,3 +822,3 @@ } else { | ||
var key = peg$currPos * 27 + 7, | ||
var key = peg$currPos * 30 + 10, | ||
cached = peg$resultsCache[key]; | ||
@@ -704,8 +833,8 @@ | ||
s0 = peg$currPos; | ||
if (input.substr(peg$currPos, 4) === peg$c10) { | ||
s1 = peg$c10; | ||
if (input.substr(peg$currPos, 4) === peg$c14) { | ||
s1 = peg$c14; | ||
peg$currPos += 4; | ||
} else { | ||
s1 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c11); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c15); } | ||
} | ||
@@ -717,8 +846,8 @@ if (s1 !== peg$FAILED) { | ||
if (s3 !== peg$FAILED) { | ||
if (input.substr(peg$currPos, 4) === peg$c12) { | ||
s4 = peg$c12; | ||
if (input.substr(peg$currPos, 4) === peg$c16) { | ||
s4 = peg$c16; | ||
peg$currPos += 4; | ||
} else { | ||
s4 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c13); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c17); } | ||
} | ||
@@ -731,3 +860,3 @@ if (s4 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s1 = peg$c14(s2, s5); | ||
s1 = peg$c18(s2, s5); | ||
s0 = s1; | ||
@@ -767,3 +896,3 @@ } else { | ||
var key = peg$currPos * 27 + 8, | ||
var key = peg$currPos * 30 + 11, | ||
cached = peg$resultsCache[key]; | ||
@@ -792,3 +921,3 @@ | ||
peg$savedPos = s0; | ||
s1 = peg$c15(s1, s2); | ||
s1 = peg$c19(s1, s2); | ||
s0 = s1; | ||
@@ -812,3 +941,3 @@ } else { | ||
var key = peg$currPos * 27 + 9, | ||
var key = peg$currPos * 30 + 12, | ||
cached = peg$resultsCache[key]; | ||
@@ -835,3 +964,3 @@ | ||
var key = peg$currPos * 27 + 10, | ||
var key = peg$currPos * 30 + 13, | ||
cached = peg$resultsCache[key]; | ||
@@ -846,8 +975,8 @@ | ||
s0 = peg$currPos; | ||
if (input.substr(peg$currPos, 5) === peg$c16) { | ||
s1 = peg$c16; | ||
if (input.substr(peg$currPos, 5) === peg$c20) { | ||
s1 = peg$c20; | ||
peg$currPos += 5; | ||
} else { | ||
s1 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c17); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c21); } | ||
} | ||
@@ -857,8 +986,8 @@ if (s1 !== peg$FAILED) { | ||
if (s2 !== peg$FAILED) { | ||
if (input.substr(peg$currPos, 2) === peg$c18) { | ||
s3 = peg$c18; | ||
if (input.substr(peg$currPos, 2) === peg$c22) { | ||
s3 = peg$c22; | ||
peg$currPos += 2; | ||
} else { | ||
s3 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c19); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c23); } | ||
} | ||
@@ -868,8 +997,8 @@ if (s3 !== peg$FAILED) { | ||
if (s4 !== peg$FAILED) { | ||
if (input.substr(peg$currPos, 2) === peg$c20) { | ||
s5 = peg$c20; | ||
if (input.substr(peg$currPos, 2) === peg$c24) { | ||
s5 = peg$c24; | ||
peg$currPos += 2; | ||
} else { | ||
s5 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c21); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c25); } | ||
} | ||
@@ -879,8 +1008,8 @@ if (s5 !== peg$FAILED) { | ||
if (s6 !== peg$FAILED) { | ||
if (input.substr(peg$currPos, 4) === peg$c22) { | ||
s7 = peg$c22; | ||
if (input.substr(peg$currPos, 4) === peg$c26) { | ||
s7 = peg$c26; | ||
peg$currPos += 4; | ||
} else { | ||
s7 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c23); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c27); } | ||
} | ||
@@ -896,3 +1025,3 @@ if (s7 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s1 = peg$c24(s2, s4, s6, s8); | ||
s1 = peg$c28(s2, s4, s6, s8); | ||
s0 = s1; | ||
@@ -944,3 +1073,3 @@ } else { | ||
var key = peg$currPos * 27 + 11, | ||
var key = peg$currPos * 30 + 14, | ||
cached = peg$resultsCache[key]; | ||
@@ -955,8 +1084,8 @@ | ||
s0 = peg$currPos; | ||
if (input.substr(peg$currPos, 4) === peg$c25) { | ||
s1 = peg$c25; | ||
if (input.substr(peg$currPos, 4) === peg$c29) { | ||
s1 = peg$c29; | ||
peg$currPos += 4; | ||
} else { | ||
s1 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c26); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c30); } | ||
} | ||
@@ -966,8 +1095,8 @@ if (s1 !== peg$FAILED) { | ||
if (s2 !== peg$FAILED) { | ||
if (input.substr(peg$currPos, 2) === peg$c20) { | ||
s3 = peg$c20; | ||
if (input.substr(peg$currPos, 2) === peg$c24) { | ||
s3 = peg$c24; | ||
peg$currPos += 2; | ||
} else { | ||
s3 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c21); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c25); } | ||
} | ||
@@ -977,8 +1106,8 @@ if (s3 !== peg$FAILED) { | ||
if (s4 !== peg$FAILED) { | ||
if (input.substr(peg$currPos, 3) === peg$c27) { | ||
s5 = peg$c27; | ||
if (input.substr(peg$currPos, 3) === peg$c31) { | ||
s5 = peg$c31; | ||
peg$currPos += 3; | ||
} else { | ||
s5 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c28); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c32); } | ||
} | ||
@@ -994,3 +1123,3 @@ if (s5 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s1 = peg$c29(s2, s4, s6); | ||
s1 = peg$c33(s2, s4, s6); | ||
s0 = s1; | ||
@@ -1034,3 +1163,3 @@ } else { | ||
var key = peg$currPos * 27 + 12, | ||
var key = peg$currPos * 30 + 15, | ||
cached = peg$resultsCache[key]; | ||
@@ -1048,7 +1177,7 @@ | ||
if (input.charCodeAt(peg$currPos) === 44) { | ||
s2 = peg$c30; | ||
s2 = peg$c34; | ||
peg$currPos++; | ||
} else { | ||
s2 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c31); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c35); } | ||
} | ||
@@ -1059,3 +1188,3 @@ if (s2 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s1 = peg$c32(s1, s3); | ||
s1 = peg$c36(s1, s3); | ||
s0 = s1; | ||
@@ -1079,3 +1208,3 @@ } else { | ||
peg$savedPos = s0; | ||
s1 = peg$c33(s1); | ||
s1 = peg$c37(s1); | ||
} | ||
@@ -1093,3 +1222,3 @@ s0 = s1; | ||
var key = peg$currPos * 27 + 13, | ||
var key = peg$currPos * 30 + 16, | ||
cached = peg$resultsCache[key]; | ||
@@ -1106,31 +1235,31 @@ | ||
if (input.charCodeAt(peg$currPos) === 43) { | ||
s2 = peg$c34; | ||
s2 = peg$c38; | ||
peg$currPos++; | ||
} else { | ||
s2 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c35); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c39); } | ||
} | ||
if (s2 === peg$FAILED) { | ||
if (input.charCodeAt(peg$currPos) === 45) { | ||
s2 = peg$c36; | ||
s2 = peg$c40; | ||
peg$currPos++; | ||
} else { | ||
s2 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c37); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c41); } | ||
} | ||
if (s2 === peg$FAILED) { | ||
if (input.charCodeAt(peg$currPos) === 32) { | ||
s2 = peg$c38; | ||
s2 = peg$c42; | ||
peg$currPos++; | ||
} else { | ||
s2 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c39); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c43); } | ||
} | ||
if (s2 === peg$FAILED) { | ||
if (input.charCodeAt(peg$currPos) === 92) { | ||
s2 = peg$c40; | ||
s2 = peg$c44; | ||
peg$currPos++; | ||
} else { | ||
s2 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c41); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c45); } | ||
} | ||
@@ -1160,3 +1289,3 @@ } | ||
peg$savedPos = s0; | ||
s1 = peg$c42(s1); | ||
s1 = peg$c46(s1); | ||
s0 = s1; | ||
@@ -1180,3 +1309,3 @@ } else { | ||
var key = peg$currPos * 27 + 14, | ||
var key = peg$currPos * 30 + 17, | ||
cached = peg$resultsCache[key]; | ||
@@ -1191,8 +1320,8 @@ | ||
s0 = peg$currPos; | ||
if (input.substr(peg$currPos, 5) === peg$c43) { | ||
s1 = peg$c43; | ||
if (input.substr(peg$currPos, 5) === peg$c47) { | ||
s1 = peg$c47; | ||
peg$currPos += 5; | ||
} else { | ||
s1 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c44); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c48); } | ||
} | ||
@@ -1203,7 +1332,7 @@ if (s1 !== peg$FAILED) { | ||
if (input.charCodeAt(peg$currPos) === 32) { | ||
s3 = peg$c38; | ||
s3 = peg$c42; | ||
peg$currPos++; | ||
} else { | ||
s3 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c39); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c43); } | ||
} | ||
@@ -1216,3 +1345,3 @@ if (s3 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s1 = peg$c45(s2, s4); | ||
s1 = peg$c49(s2, s4); | ||
s0 = s1; | ||
@@ -1248,3 +1377,3 @@ } else { | ||
var key = peg$currPos * 27 + 15, | ||
var key = peg$currPos * 30 + 18, | ||
cached = peg$resultsCache[key]; | ||
@@ -1262,3 +1391,3 @@ | ||
peg$savedPos = s0; | ||
s1 = peg$c46(s1); | ||
s1 = peg$c50(s1); | ||
} | ||
@@ -1275,3 +1404,3 @@ s0 = s1; | ||
var key = peg$currPos * 27 + 16, | ||
var key = peg$currPos * 30 + 19, | ||
cached = peg$resultsCache[key]; | ||
@@ -1300,3 +1429,3 @@ | ||
peg$savedPos = s0; | ||
s1 = peg$c47(s1, s2); | ||
s1 = peg$c51(s1, s2); | ||
s0 = s1; | ||
@@ -1320,3 +1449,3 @@ } else { | ||
var key = peg$currPos * 27 + 17, | ||
var key = peg$currPos * 30 + 20, | ||
cached = peg$resultsCache[key]; | ||
@@ -1331,25 +1460,25 @@ | ||
s0 = peg$currPos; | ||
if (input.substr(peg$currPos, 3) === peg$c48) { | ||
s1 = peg$c48; | ||
if (input.substr(peg$currPos, 3) === peg$c52) { | ||
s1 = peg$c52; | ||
peg$currPos += 3; | ||
} else { | ||
s1 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c49); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c53); } | ||
} | ||
if (s1 === peg$FAILED) { | ||
if (input.substr(peg$currPos, 7) === peg$c50) { | ||
s1 = peg$c50; | ||
if (input.substr(peg$currPos, 7) === peg$c54) { | ||
s1 = peg$c54; | ||
peg$currPos += 7; | ||
} else { | ||
s1 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c51); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c55); } | ||
} | ||
} | ||
if (s1 !== peg$FAILED) { | ||
if (input.substr(peg$currPos, 11) === peg$c52) { | ||
s2 = peg$c52; | ||
if (input.substr(peg$currPos, 11) === peg$c56) { | ||
s2 = peg$c56; | ||
peg$currPos += 11; | ||
} else { | ||
s2 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c53); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c57); } | ||
} | ||
@@ -1362,3 +1491,3 @@ if (s2 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s1 = peg$c54(s1, s3); | ||
s1 = peg$c58(s1, s3); | ||
s0 = s1; | ||
@@ -1390,3 +1519,3 @@ } else { | ||
var key = peg$currPos * 27 + 18, | ||
var key = peg$currPos * 30 + 21, | ||
cached = peg$resultsCache[key]; | ||
@@ -1401,8 +1530,8 @@ | ||
s0 = peg$currPos; | ||
if (input.substr(peg$currPos, 9) === peg$c55) { | ||
s1 = peg$c55; | ||
if (input.substr(peg$currPos, 9) === peg$c59) { | ||
s1 = peg$c59; | ||
peg$currPos += 9; | ||
} else { | ||
s1 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c56); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c60); } | ||
} | ||
@@ -1414,8 +1543,8 @@ if (s1 !== peg$FAILED) { | ||
if (s3 !== peg$FAILED) { | ||
if (input.substr(peg$currPos, 9) === peg$c57) { | ||
s4 = peg$c57; | ||
if (input.substr(peg$currPos, 9) === peg$c61) { | ||
s4 = peg$c61; | ||
peg$currPos += 9; | ||
} else { | ||
s4 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c58); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c62); } | ||
} | ||
@@ -1428,3 +1557,3 @@ if (s4 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s1 = peg$c59(s2, s5); | ||
s1 = peg$c63(s2, s5); | ||
s0 = s1; | ||
@@ -1464,3 +1593,3 @@ } else { | ||
var key = peg$currPos * 27 + 19, | ||
var key = peg$currPos * 30 + 22, | ||
cached = peg$resultsCache[key]; | ||
@@ -1475,8 +1604,8 @@ | ||
s0 = peg$currPos; | ||
if (input.substr(peg$currPos, 6) === peg$c60) { | ||
s1 = peg$c60; | ||
if (input.substr(peg$currPos, 6) === peg$c64) { | ||
s1 = peg$c64; | ||
peg$currPos += 6; | ||
} else { | ||
s1 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c61); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c65); } | ||
} | ||
@@ -1487,7 +1616,7 @@ if (s1 !== peg$FAILED) { | ||
if (input.charCodeAt(peg$currPos) === 32) { | ||
s3 = peg$c38; | ||
s3 = peg$c42; | ||
peg$currPos++; | ||
} else { | ||
s3 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c39); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c43); } | ||
} | ||
@@ -1500,3 +1629,3 @@ if (s3 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s1 = peg$c62(s4); | ||
s1 = peg$c66(s4); | ||
s0 = s1; | ||
@@ -1525,8 +1654,8 @@ } else { | ||
s0 = peg$currPos; | ||
if (input.substr(peg$currPos, 6) === peg$c60) { | ||
s1 = peg$c60; | ||
if (input.substr(peg$currPos, 6) === peg$c64) { | ||
s1 = peg$c64; | ||
peg$currPos += 6; | ||
} else { | ||
s1 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c61); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c65); } | ||
} | ||
@@ -1562,3 +1691,3 @@ if (s1 !== peg$FAILED) { | ||
var key = peg$currPos * 27 + 20, | ||
var key = peg$currPos * 30 + 23, | ||
cached = peg$resultsCache[key]; | ||
@@ -1572,3 +1701,3 @@ | ||
if (peg$c63.test(input.charAt(peg$currPos))) { | ||
if (peg$c67.test(input.charAt(peg$currPos))) { | ||
s0 = input.charAt(peg$currPos); | ||
@@ -1578,3 +1707,3 @@ peg$currPos++; | ||
s0 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c64); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c68); } | ||
} | ||
@@ -1590,3 +1719,3 @@ | ||
var key = peg$currPos * 27 + 21, | ||
var key = peg$currPos * 30 + 24, | ||
cached = peg$resultsCache[key]; | ||
@@ -1601,15 +1730,15 @@ | ||
if (input.charCodeAt(peg$currPos) === 10) { | ||
s0 = peg$c65; | ||
s0 = peg$c69; | ||
peg$currPos++; | ||
} else { | ||
s0 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c66); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c70); } | ||
} | ||
if (s0 === peg$FAILED) { | ||
if (input.substr(peg$currPos, 2) === peg$c67) { | ||
s0 = peg$c67; | ||
if (input.substr(peg$currPos, 2) === peg$c71) { | ||
s0 = peg$c71; | ||
peg$currPos += 2; | ||
} else { | ||
s0 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c68); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c72); } | ||
} | ||
@@ -1629,3 +1758,3 @@ } | ||
var key = peg$currPos * 27 + 22, | ||
var key = peg$currPos * 30 + 25, | ||
cached = peg$resultsCache[key]; | ||
@@ -1652,3 +1781,3 @@ | ||
var key = peg$currPos * 27 + 23, | ||
var key = peg$currPos * 30 + 26, | ||
cached = peg$resultsCache[key]; | ||
@@ -1669,3 +1798,3 @@ | ||
s1 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c69); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c73); } | ||
} | ||
@@ -1688,3 +1817,3 @@ peg$silentFails--; | ||
var key = peg$currPos * 27 + 24, | ||
var key = peg$currPos * 30 + 27, | ||
cached = peg$resultsCache[key]; | ||
@@ -1700,3 +1829,3 @@ | ||
s1 = []; | ||
if (peg$c70.test(input.charAt(peg$currPos))) { | ||
if (peg$c74.test(input.charAt(peg$currPos))) { | ||
s2 = input.charAt(peg$currPos); | ||
@@ -1706,3 +1835,3 @@ peg$currPos++; | ||
s2 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c71); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c75); } | ||
} | ||
@@ -1712,3 +1841,3 @@ if (s2 !== peg$FAILED) { | ||
s1.push(s2); | ||
if (peg$c70.test(input.charAt(peg$currPos))) { | ||
if (peg$c74.test(input.charAt(peg$currPos))) { | ||
s2 = input.charAt(peg$currPos); | ||
@@ -1718,3 +1847,3 @@ peg$currPos++; | ||
s2 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c71); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c75); } | ||
} | ||
@@ -1727,3 +1856,3 @@ } | ||
peg$savedPos = s0; | ||
s1 = peg$c42(s1); | ||
s1 = peg$c46(s1); | ||
} | ||
@@ -1740,3 +1869,3 @@ s0 = s1; | ||
var key = peg$currPos * 27 + 25, | ||
var key = peg$currPos * 30 + 28, | ||
cached = peg$resultsCache[key]; | ||
@@ -1752,3 +1881,3 @@ | ||
s1 = []; | ||
if (peg$c72.test(input.charAt(peg$currPos))) { | ||
if (peg$c76.test(input.charAt(peg$currPos))) { | ||
s2 = input.charAt(peg$currPos); | ||
@@ -1758,3 +1887,3 @@ peg$currPos++; | ||
s2 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c73); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c77); } | ||
} | ||
@@ -1764,3 +1893,3 @@ if (s2 !== peg$FAILED) { | ||
s1.push(s2); | ||
if (peg$c72.test(input.charAt(peg$currPos))) { | ||
if (peg$c76.test(input.charAt(peg$currPos))) { | ||
s2 = input.charAt(peg$currPos); | ||
@@ -1770,3 +1899,3 @@ peg$currPos++; | ||
s2 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c73); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c77); } | ||
} | ||
@@ -1779,3 +1908,3 @@ } | ||
peg$savedPos = s0; | ||
s1 = peg$c42(s1); | ||
s1 = peg$c46(s1); | ||
} | ||
@@ -1792,3 +1921,3 @@ s0 = s1; | ||
var key = peg$currPos * 27 + 26, | ||
var key = peg$currPos * 30 + 29, | ||
cached = peg$resultsCache[key]; | ||
@@ -1804,3 +1933,3 @@ | ||
s1 = []; | ||
if (peg$c74.test(input.charAt(peg$currPos))) { | ||
if (peg$c78.test(input.charAt(peg$currPos))) { | ||
s2 = input.charAt(peg$currPos); | ||
@@ -1810,3 +1939,3 @@ peg$currPos++; | ||
s2 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c75); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c79); } | ||
} | ||
@@ -1816,3 +1945,3 @@ if (s2 !== peg$FAILED) { | ||
s1.push(s2); | ||
if (peg$c74.test(input.charAt(peg$currPos))) { | ||
if (peg$c78.test(input.charAt(peg$currPos))) { | ||
s2 = input.charAt(peg$currPos); | ||
@@ -1822,3 +1951,3 @@ peg$currPos++; | ||
s2 = peg$FAILED; | ||
if (peg$silentFails === 0) { peg$fail(peg$c75); } | ||
if (peg$silentFails === 0) { peg$fail(peg$c79); } | ||
} | ||
@@ -1831,3 +1960,3 @@ } | ||
peg$savedPos = s0; | ||
s1 = peg$c76(s1); | ||
s1 = peg$c80(s1); | ||
} | ||
@@ -1842,3 +1971,3 @@ s0 = s1; | ||
function postProcessDiff (header, file_modes, patch) { | ||
function postProcessDiff (header, file_modes, patch, binary) { | ||
let status | ||
@@ -1852,3 +1981,4 @@ if (file_modes.old_mode && !file_modes.new_mode) { | ||
hunks: patch ? patch.hunks : [], | ||
status: 'deleted' | ||
status: 'deleted', | ||
binary: !!binary | ||
} | ||
@@ -1862,6 +1992,7 @@ } else if (!file_modes.old_mode && file_modes.new_mode) { | ||
hunks: patch ? patch.hunks : [], | ||
status: 'added' | ||
status: 'added', | ||
binary: !!binary | ||
} | ||
} else if (file_modes.old_mode && file_modes.new_mode) { | ||
if (patch) { | ||
if (patch || binary) { | ||
return { | ||
@@ -1872,7 +2003,8 @@ newPath: header.file_name, | ||
newMode: file_modes.new_mode, | ||
hunks: patch.hunks, | ||
status: 'modified' | ||
hunks: patch ? patch.hunks : [], | ||
status: 'modified', | ||
binary: !!binary | ||
} | ||
} else { | ||
throw new Error('patch expected') | ||
throw new Error('patch or binary expected') | ||
} | ||
@@ -1884,3 +2016,11 @@ } else { | ||
function postProcessMergeConflictDiff (filePath, patch, binary) { | ||
patch = patch || {} | ||
patch.filePath = filePath | ||
patch.status = 'unmerged' | ||
patch.binary = !!binary | ||
return patch | ||
} | ||
peg$result = peg$startRuleFunction(); | ||
@@ -1887,0 +2027,0 @@ |
{ | ||
"name": "what-the-diff", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "diff parsing library", | ||
@@ -19,2 +19,3 @@ "main": "index.js", | ||
"devDependencies": { | ||
"dedent-js": "^1.0.1", | ||
"nodeunit": "^0.10.2", | ||
@@ -21,0 +22,0 @@ "pegjs": "^0.10.0" |
# JavaScript Diff Parser | ||
![](https://pbs.twimg.com/media/ByZVWXgIIAA5Y2D.png:large) | ||
Credit: [@eightballart](https://twitter.com/EightballArt/status/515195030546690048) | ||
@@ -5,0 +6,0 @@ |
var diff = require('../') | ||
var dedent = require('dedent-js') | ||
var fs = require('fs') | ||
@@ -7,11 +8,13 @@ | ||
exports.testSimplePatch = function(test) { | ||
var str = `diff --git file.txt file.txt | ||
index 83db48f..bf269f4 100644 | ||
--- file.txt | ||
+++ file.txt | ||
@@ -1,3 +1,3 @@ | ||
line1 | ||
-line2 | ||
+new line | ||
line3` | ||
var str = dedent` | ||
diff --git file.txt file.txt | ||
index 83db48f..bf269f4 100644 | ||
--- file.txt | ||
+++ file.txt | ||
@@ -1,3 +1,3 @@ | ||
line1 | ||
-line2 | ||
+new line | ||
line3 | ||
` | ||
@@ -39,3 +42,4 @@ const output = diff.parse(str) | ||
} | ||
] | ||
], | ||
binary: false | ||
} | ||
@@ -47,9 +51,11 @@ ]) | ||
exports.testNewPatch = function(test) { | ||
var str = `diff --git file.txt file.txt | ||
new file mode 100644 | ||
index 0000000..dab621c | ||
--- /dev/null | ||
+++ file.txt | ||
@@ -0,0 +1 @@ | ||
+foo` | ||
var str = dedent` | ||
diff --git file.txt file.txt | ||
new file mode 100644 | ||
index 0000000..dab621c | ||
--- /dev/null | ||
+++ file.txt | ||
@@ -0,0 +1 @@ | ||
+foo | ||
` | ||
@@ -72,3 +78,4 @@ const output = diff.parse(str) | ||
} | ||
] | ||
], | ||
binary: false | ||
} | ||
@@ -80,9 +87,11 @@ ]) | ||
exports.testRemovedPatch = function(test) { | ||
var str = `diff --git file.txt file.txt | ||
deleted file mode 100644 | ||
index dab621c..0000000 | ||
--- file.txt | ||
+++ /dev/null | ||
@@ -1 +0,0 @@ | ||
-foo` | ||
var str = dedent` | ||
diff --git file.txt file.txt | ||
deleted file mode 100644 | ||
index dab621c..0000000 | ||
--- file.txt | ||
+++ /dev/null | ||
@@ -1 +0,0 @@ | ||
-foo | ||
` | ||
@@ -105,3 +114,4 @@ const output = diff.parse(str) | ||
} | ||
] | ||
], | ||
binary: false | ||
} | ||
@@ -113,13 +123,15 @@ ]) | ||
exports.testFileModeChange = function(test) { | ||
var str = `diff --git file.txt file.txt | ||
old mode 100644 | ||
new mode 100755 | ||
index 83db48f..bf269f4 | ||
--- file.txt | ||
+++ file.txt | ||
@@ -1,3 +1,3 @@ | ||
line1 | ||
-line2 | ||
+new line | ||
line3` | ||
var str = dedent` | ||
diff --git file.txt file.txt | ||
old mode 100644 | ||
new mode 100755 | ||
index 83db48f..bf269f4 | ||
--- file.txt | ||
+++ file.txt | ||
@@ -1,3 +1,3 @@ | ||
line1 | ||
-line2 | ||
+new line | ||
line3 | ||
` | ||
@@ -147,3 +159,4 @@ const output = diff.parse(str) | ||
} | ||
] | ||
], | ||
binary: false | ||
} | ||
@@ -155,5 +168,7 @@ ]) | ||
exports.testNewEmptyFile = function(test) { | ||
var str = `diff --git newfile.txt newfile.txt | ||
new file mode 100644 | ||
index 0000000..e69de29` | ||
var str = dedent` | ||
diff --git newfile.txt newfile.txt | ||
new file mode 100644 | ||
index 0000000..e69de29 | ||
` | ||
@@ -168,3 +183,4 @@ const output = diff.parse(str) | ||
hunks: [], | ||
status: 'added' | ||
status: 'added', | ||
binary: false | ||
} | ||
@@ -176,9 +192,11 @@ ]) | ||
exports.testSingleLineHunk = function(test) { | ||
var str = `diff --git file.txt file.txt | ||
index 83db48f..bf269f4 100644 | ||
--- file.txt | ||
+++ file.txt | ||
@@ -1 +1 @@ | ||
-line1 | ||
+line2` | ||
var str = dedent` | ||
diff --git file.txt file.txt | ||
index 83db48f..bf269f4 100644 | ||
--- file.txt | ||
+++ file.txt | ||
@@ -1 +1 @@ | ||
-line1 | ||
+line2 | ||
` | ||
@@ -204,3 +222,4 @@ const output = diff.parse(str) | ||
} | ||
] | ||
], | ||
binary: false | ||
} | ||
@@ -212,18 +231,20 @@ ]) | ||
exports.testMultipleHunks = function(test) { | ||
var str = `diff --git file.txt file.txt | ||
index 83db48f..bf269f4 100644 | ||
--- file.txt | ||
+++ file.txt | ||
@@ -1,5 +1,4 @@ | ||
line1 | ||
-line2 | ||
line3 | ||
line4 | ||
line5 | ||
@@ -15,4 +14,5 @@ | ||
line6 | ||
line7 | ||
line8 | ||
+line2 | ||
line9` | ||
var str = dedent` | ||
diff --git file.txt file.txt | ||
index 83db48f..bf269f4 100644 | ||
--- file.txt | ||
+++ file.txt | ||
@@ -1,5 +1,4 @@ | ||
line1 | ||
-line2 | ||
line3 | ||
line4 | ||
line5 | ||
@@ -15,4 +14,5 @@ | ||
line6 | ||
line7 | ||
line8 | ||
+line2 | ||
line9 | ||
` | ||
@@ -265,3 +286,4 @@ const output = diff.parse(str) | ||
} | ||
] | ||
], | ||
binary: false | ||
} | ||
@@ -273,10 +295,12 @@ ]) | ||
exports.testRemovedEOFNL = function(test) { | ||
var str = `diff --git file.txt file.txt | ||
index a999a0c..266014b 100644 | ||
--- file.txt | ||
+++ file.txt | ||
@@ -1 +1 @@ | ||
-line | ||
+line | ||
\ No newline at end of file` | ||
var str = dedent` | ||
diff --git file.txt file.txt | ||
index a999a0c..266014b 100644 | ||
--- file.txt | ||
+++ file.txt | ||
@@ -1 +1 @@ | ||
-line | ||
+line | ||
\ No newline at end of file | ||
` | ||
@@ -303,3 +327,4 @@ const output = diff.parse(str) | ||
} | ||
] | ||
], | ||
binary: false | ||
} | ||
@@ -311,10 +336,12 @@ ]) | ||
exports.testAddedEOFNL = function(test) { | ||
var str = `diff --git file.txt file.txt | ||
index 266014b..a999a0c 100644 | ||
--- file.txt | ||
+++ file.txt | ||
@@ -1 +1 @@ | ||
-line | ||
\ No newline at end of file | ||
+line` | ||
var str = dedent` | ||
diff --git file.txt file.txt | ||
index 266014b..a999a0c 100644 | ||
--- file.txt | ||
+++ file.txt | ||
@@ -1 +1 @@ | ||
-line | ||
\ No newline at end of file | ||
+line | ||
` | ||
@@ -341,3 +368,4 @@ const output = diff.parse(str) | ||
} | ||
] | ||
], | ||
binary: false | ||
} | ||
@@ -349,11 +377,13 @@ ]) | ||
exports.testEmptyHunkLine = function(test) { | ||
var str = `diff --git file.txt file.txt | ||
index 83db48f..bf269f4 100644 | ||
--- file.txt | ||
+++ file.txt | ||
@@ -1,3 +1,3 @@ | ||
line1 | ||
-line2 | ||
+ | ||
line3` | ||
var str = dedent` | ||
diff --git file.txt file.txt | ||
index 83db48f..bf269f4 100644 | ||
--- file.txt | ||
+++ file.txt | ||
@@ -1,3 +1,3 @@ | ||
line1 | ||
-line2 | ||
+ | ||
line3 | ||
` | ||
@@ -381,3 +411,4 @@ const output = diff.parse(str) | ||
} | ||
] | ||
], | ||
binary: false | ||
} | ||
@@ -389,16 +420,21 @@ ]) | ||
exports.testMergeConflicts = function(test) { | ||
var str = `diff --cc modified-on-both.txt | ||
index 5b7855c,1353022..0000000 | ||
--- modified-on-both.txt | ||
+++ modified-on-both.txt | ||
@@@ -1,1 -1,1 +1,7 @@@ | ||
++<<<<<<< HEAD | ||
+master modification | ||
++||||||| merged common ancestors | ||
++text | ||
++======= | ||
+ branch modification | ||
++>>>>>>> branch | ||
* Unmerged path removed-on-branch.txt | ||
* Unmerged path removed-on-master.txt` | ||
var str = dedent` | ||
diff --cc modified-on-both.txt | ||
index 5b7855c,1353022..0000000 | ||
--- modified-on-both.txt | ||
+++ modified-on-both.txt | ||
@@@ -1,1 -1,1 +1,7 @@@ | ||
++<<<<<<< HEAD | ||
+master modification | ||
++||||||| merged common ancestors | ||
++text | ||
++======= | ||
+ branch modification | ||
++>>>>>>> branch | ||
* Unmerged path removed-on-branch.txt | ||
* Unmerged path removed-on-master.txt | ||
diff --cc image.gif | ||
index e6551c7,5f88da9..0000000 | ||
Binary files differ | ||
` | ||
@@ -428,11 +464,19 @@ const output = diff.parse(str) | ||
} | ||
] | ||
], | ||
binary: false | ||
}, | ||
{ | ||
filePath: 'removed-on-branch.txt', | ||
status: 'unmerged' | ||
status: 'unmerged', | ||
binary: false | ||
}, | ||
{ | ||
filePath: 'removed-on-master.txt', | ||
status: 'unmerged' | ||
status: 'unmerged', | ||
binary: false | ||
}, | ||
{ | ||
filePath: 'image.gif', | ||
status: 'unmerged', | ||
binary: true | ||
} | ||
@@ -442,1 +486,49 @@ ]) | ||
} | ||
exports.testBinaryFiles = function(test) { | ||
var str = dedent` | ||
diff --git one.gif one.gif | ||
new file mode 100644 | ||
index 0000000..9243b23 | ||
Binary files /dev/null and one.gif differ | ||
diff --git two.gif two.gif | ||
index 9243b23..e26b70a 100644 | ||
Binary files two.gif and two.gif differ | ||
diff --git three.gif three.gif | ||
deleted file mode 100644 | ||
index e26b70a..0000000 | ||
Binary files three.gif and /dev/null differ | ||
` | ||
const output = diff.parse(str) | ||
assert.deepEqual(output, [ | ||
{ | ||
oldPath: null, | ||
newPath: 'one.gif', | ||
oldMode: null, | ||
newMode: '100644', | ||
status: 'added', | ||
hunks: [], | ||
binary: true | ||
}, | ||
{ | ||
oldPath: 'two.gif', | ||
newPath: 'two.gif', | ||
oldMode: '100644', | ||
newMode: '100644', | ||
status: 'modified', | ||
hunks: [], | ||
binary: true | ||
}, | ||
{ | ||
oldPath: 'three.gif', | ||
newPath: null, | ||
oldMode: '100644', | ||
newMode: null, | ||
status: 'deleted', | ||
hunks: [], | ||
binary: true | ||
}, | ||
]) | ||
test.done() | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
65404
9
2174
56
3