Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong result when paring some diff that contains deleted sql comment starting with -- #41

Closed
jiashanyao opened this issue Oct 8, 2021 · 3 comments · Fixed by #42
Closed

Comments

@jiashanyao
Copy link

Here is a test diff input to reproduce the bug

diff --git a/test.sql b/test.sql
index 305feaa..70865e7 100644
--- a/test.sql
+++ b/test.sql
@@ -1,10 +1,9 @@
--- Person
-create table person
-( id                   		bigint,
-  primary key ( id ) );
-
-
 -- Photo
 create table photo
 ( id                      bigint,
   primary key (id ) );
+
+-- Person
+create table person
+( id                   		bigint,
+  primary key ( id ) );

And the parsed result is

[
  {
    "chunks": [
      {
        "content": "@@ -1,10 +1,9 @@",
        "changes": [
          {
            "type": "del",
            "del": true,
            "ln": 1,
            "content": "-create table person"
          },
          {
            "type": "del",
            "del": true,
            "ln": 2,
            "content": "-( id                   \t\tbigint,"
          },
          {
            "type": "del",
            "del": true,
            "ln": 3,
            "content": "-  primary key ( id ) );"
          },
          {
            "type": "del",
            "del": true,
            "ln": 4,
            "content": "-"
          },
          {
            "type": "del",
            "del": true,
            "ln": 5,
            "content": "-"
          },
          {
            "type": "normal",
            "normal": true,
            "ln1": 6,
            "ln2": 1,
            "content": " -- Photo"
          },
          {
            "type": "normal",
            "normal": true,
            "ln1": 7,
            "ln2": 2,
            "content": " create table photo"
          },
          {
            "type": "normal",
            "normal": true,
            "ln1": 8,
            "ln2": 3,
            "content": " ( id                      bigint,"
          },
          {
            "type": "normal",
            "normal": true,
            "ln1": 9,
            "ln2": 4,
            "content": "   primary key (id ) );"
          },
          {
            "type": "add",
            "add": true,
            "ln": 5,
            "content": "+"
          },
          {
            "type": "add",
            "add": true,
            "ln": 6,
            "content": "+-- Person"
          },
          {
            "type": "add",
            "add": true,
            "ln": 7,
            "content": "+create table person"
          },
          {
            "type": "add",
            "add": true,
            "ln": 8,
            "content": "+( id                   \t\tbigint,"
          },
          {
            "type": "add",
            "add": true,
            "ln": 9,
            "content": "+  primary key ( id ) );"
          }
        ],
        "oldStart": 1,
        "oldLines": 10,
        "newStart": 1,
        "newLines": 9
      }
    ],
    "deletions": 0,
    "additions": 0,
    "from": "test.sql",
    "to": "test.sql",
    "index": [
      "305feaa..70865e7",
      "100644"
    ]
  },
  {
    "chunks": [],
    "deletions": 5,
    "additions": 5,
    "from": "Person"
  }
]

which is wrong.

@mironiasty
Copy link
Contributor

I found similar issue, but for files that contains lines like ++ some text. It looks like it could be fixed in two ways:

  • By improving regex to better detect added/removed files from patch
  • By checking if toFile line is right after fromFile

@sergeyt If I would create correct fix for it, would it be merged? (AKA is this repo still maintained)

@sergeyt
Copy link
Owner

sergeyt commented Nov 17, 2021

@mironiasty Sure. As usual, fixes should be covered by unit tests and all tests should be passing. I am happy to release new version

@mironiasty
Copy link
Contributor

small update: I was working on fix. But looks like this bug can't be really fixed without using information from chunk, to get number of lines with changed data. Any other solution I tried, either won't really fix it or it will introduce some breaking changes. I hope I will have some time soon to implement proper fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants