langram / node-diff3

This is a node.js library for text diffing and three-way-merge. It originally come from project Synchrotron, created by Tony Garnock-Jones. For more detail please visit: http://homepages.kcbbs.gen.nz/tonyg/projects/synchrotron.html.
MIT License
12 stars 5 forks source link

Ignores first conflict #5

Open vptes1 opened 6 years ago

vptes1 commented 6 years ago
nodeDiff3.merge(
    "one\n22222\nthree\n44\nfive\n6666", 
    "one\ntwo\nthree\nfour\nfive\nsix", 
    "one\nTTTTTT\nthree\nF\nfive\nSSSSS"
)

currently returns

{
    "conflict": true,
    "result": [
        "o",
        "n",
        "e",
        "\n",
        "t",
        "w",
        "o",
        "\n",
        "t",
        "h",
        "r",
        "e",
        "e",
        "\n",
        "\n<<<<<<<<<\n",
        "44",
        "\n=========\n",
        "F",
        "\n>>>>>>>>>\n",
        "\n",
        "f",
        "i",
        "v",
        "e",
        "\n",
        "\n<<<<<<<<<\n",
        "6666",
        "\n=========\n",
        "SSSSS",
        "\n>>>>>>>>>\n"
    ]
}

Is it just me or does it overlook the very first conflict, involving two?

bhousel commented 6 years ago

Hey @vptes1 this looks to be caused by the hunk-sorting bug #3 this is fixed by PR #4

I'm maintaining an updated version of this library that includes the fix: https://github.com/bhousel/node-diff3

When I run it, I get this:

$ node
> const Diff3 = require('.');
undefined

> Diff3.merge(
    "one\n22222\nthree\n44\nfive\n6666", 
    "one\ntwo\nthree\nfour\nfive\nsix", 
    "one\nTTTTTT\nthree\nF\nfive\nSSSSS");

{ 
  conflict: true,
  result: [
     'o',
     'n',
     'e',
     '\n',
     '\n<<<<<<<<<\n',
     '22222',
     '\n=========\n',
     'TTTTTT',
     '\n>>>>>>>>>\n',
     '\n',
     't',
     'h',
     'r',
     'e',
     'e',
     '\n',
     '\n<<<<<<<<<\n',
     '44',
     '\n=========\n',
     'F',
     '\n>>>>>>>>>\n',
     '\n',
     'f',
     'i',
     'v',
     'e',
     '\n',
     '\n<<<<<<<<<\n',
     '6666',
     '\n=========\n',
     'SSSSS',
     '\n>>>>>>>>>\n' 
  ] 
}