yeonjuan / parse-git-diff

parse git diff
MIT License
28 stars 3 forks source link

Files lost in diff #22

Closed kentcdodds closed 1 year ago

kentcdodds commented 1 year ago

Here's the diff:

diff --git var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.problem.outlet/xn2ci7n8yna/app/assets/img.png var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.solution.outlet/xn2ci7n8yna/app/assets/img.png
index d7077fa..84d259b 100644
Binary files var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.problem.outlet/xn2ci7n8yna/app/assets/img.png and var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.solution.outlet/xn2ci7n8yna/app/assets/img.png differ
diff --git var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.solution.outlet/xn2ci7n8yna/app/assets/img2.png var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.solution.outlet/xn2ci7n8yna/app/assets/img2.png
new file mode 100644
index 0000000..636c497
Binary files /dev/null and var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.solution.outlet/xn2ci7n8yna/app/assets/img2.png differ
diff --git var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.problem.outlet/xn2ci7n8yna/app/root.tsx var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.solution.outlet/xn2ci7n8yna/app/root.tsx
index f4fc7f7..703fce2 100644
--- var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.problem.outlet/xn2ci7n8yna/app/root.tsx
+++ var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.solution.outlet/xn2ci7n8yna/app/root.tsx
@@ -7,9 +7,10 @@ import {
    Scripts,
    ScrollRestoration,
 } from '@remix-run/react'
-import tailwindStylesheetUrl from './styles/tailwind.css'
 import { KCDShop } from './kcdshop.tsx'

+import tailwindStylesheetUrl from './styles/tailwind.css'
+
 export const links: LinksFunction = () => {
    return [{ rel: 'stylesheet', href: tailwindStylesheetUrl }]
 }
diff --git var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.problem.outlet/xn2ci7n8yna/app/routes/deleted.tsx var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.problem.outlet/xn2ci7n8yna/app/routes/deleted.tsx
deleted file mode 100644
index 9080896..0000000
--- var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.problem.outlet/xn2ci7n8yna/app/routes/deleted.tsx
+++ /dev/null
@@ -1,5 +0,0 @@
-import { json } from '@remix-run/node'
-
-export async function loader() {
-   return json({ iAm: 'deleted' })
-}
diff --git var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.problem.outlet/xn2ci7n8yna/app/routes/index.tsx var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.solution.outlet/xn2ci7n8yna/app/routes/index.tsx
index ceb48f8..c5f1b30 100644
--- var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.problem.outlet/xn2ci7n8yna/app/routes/index.tsx
+++ var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.solution.outlet/xn2ci7n8yna/app/routes/index.tsx
@@ -1,12 +1,7 @@
-import { Link } from '@remix-run/react'
-
 export default function Index() {
    return (
-       <main className="relative min-h-screen bg-white">
+       <main className="relative min-h-screen bg-white sm:flex sm:items-center sm:justify-center">
            <h1>Welcome to the app</h1>
-           <Link to="/whatever" className="text-blue-800 underline">
-               Go to "/whatever"
-           </Link>
        </main>
    )
 }
diff --git var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.solution.outlet/xn2ci7n8yna/app/routes/parent.tsx var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.solution.outlet/xn2ci7n8yna/app/routes/parent.tsx
new file mode 100644
index 0000000..9fd1945
--- /dev/null
+++ var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.solution.outlet/xn2ci7n8yna/app/routes/parent.tsx
@@ -0,0 +1,3 @@
+export default function Parent() {
+   return <p>I am a parent</p>
+}
diff --git var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.problem.outlet/xn2ci7n8yna/package.json var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.solution.outlet/xn2ci7n8yna/package.json
index 35f55ad..b4c5e0a 100644
--- var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.problem.outlet/xn2ci7n8yna/package.json
+++ var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.solution.outlet/xn2ci7n8yna/package.json
@@ -1,19 +1,14 @@
 {
-  "name": "exercises.01.nested-routing.01.problem.outlet",
+  "name": "exercises.01.nested-routing.01.solution.outlet",
   "private": true,
   "sideEffects": false,
-  "kcd-workshop": {
-    "testRequiresApp": true,
-    "scripts": {
-      "test": "echo \"\\x1b[36mhello\\x1b[37mworld\" && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi"
-    }
-  },
   "type": "module",
   "scripts": {
     "build": "run-s build:*",
     "build:remix": "remix build",
     "build:server": "tsx ./other/build-server.ts",
     "dev": "remix dev -c \"tsx ./index.js\" --manual",
+    "test": "echo TODO",
     "format": "prettier --write .",
     "lint": "eslint --cache --cache-location ./node_modules/.cache/eslint .",
     "start": "cross-env NODE_ENV=production node .",

And here's the result of calling parseGitDiff(diffOutput, { noPrefix: true }):

[]
kentcdodds commented 1 year ago

To be clear, this is with v0.0.12

yeonjuan commented 1 year ago

Thanks! It's fixed and released in v0.0.13.

Here is the output, that i tested with the given diff!.

{
  "type": "GitDiff",
  "files": [
    {
      "type": "ChangedFile",
      "chunks": [
        {
          "type": "BinaryFilesChunk",
          "pathBefore": "var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.problem.outlet/xn2ci7n8yna/app/assets/img.png",
          "pathAfter": "var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.solution.outlet/xn2ci7n8yna/app/assets/img.png"
        }
      ],
      "path": "var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.solution.outlet/xn2ci7n8yna/app/assets/img.png"
    },
    {
      "type": "AddedFile",
      "chunks": [
        {
          "type": "BinaryFilesChunk",
          "pathBefore": "/dev/null",
          "pathAfter": "var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.solution.outlet/xn2ci7n8yna/app/assets/img2.png"
        }
      ],
      "path": "var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.solution.outlet/xn2ci7n8yna/app/assets/img2.png"
    },
    {
      "type": "ChangedFile",
      "chunks": [
        {
          "context": "import {",
          "type": "Chunk",
          "toFileRange": {
            "start": 7,
            "lines": 10
          },
          "fromFileRange": {
            "start": 7,
            "lines": 9
          },
          "changes": [
            {
              "type": "UnchangedLine",
              "lineBefore": 7,
              "lineAfter": 7,
              "content": "\tScripts,"
            },
            {
              "type": "UnchangedLine",
              "lineBefore": 8,
              "lineAfter": 8,
              "content": "\tScrollRestoration,"
            },
            {
              "type": "UnchangedLine",
              "lineBefore": 9,
              "lineAfter": 9,
              "content": "} from '@remix-run/react'"
            },
            {
              "type": "DeletedLine",
              "lineBefore": 10,
              "content": "import tailwindStylesheetUrl from './styles/tailwind.css'"
            },
            {
              "type": "UnchangedLine",
              "lineBefore": 11,
              "lineAfter": 10,
              "content": "import { KCDShop } from './kcdshop.tsx'"
            },
            {
              "type": "UnchangedLine",
              "lineBefore": 12,
              "lineAfter": 11,
              "content": ""
            },
            {
              "type": "AddedLine",
              "lineAfter": 12,
              "content": "import tailwindStylesheetUrl from './styles/tailwind.css'"
            },
            {
              "type": "AddedLine",
              "lineAfter": 13,
              "content": ""
            },
            {
              "type": "UnchangedLine",
              "lineBefore": 13,
              "lineAfter": 14,
              "content": "export const links: LinksFunction = () => {"
            },
            {
              "type": "UnchangedLine",
              "lineBefore": 14,
              "lineAfter": 15,
              "content": "\treturn [{ rel: 'stylesheet', href: tailwindStylesheetUrl }]"
            },
            {
              "type": "UnchangedLine",
              "lineBefore": 15,
              "lineAfter": 16,
              "content": "}"
            }
          ]
        }
      ],
      "path": "var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.solution.outlet/xn2ci7n8yna/app/root.tsx"
    },
    {
      "type": "DeletedFile",
      "chunks": [
        {
          "type": "Chunk",
          "toFileRange": {
            "start": 0,
            "lines": 0
          },
          "fromFileRange": {
            "start": 1,
            "lines": 5
          },
          "changes": [
            {
              "type": "DeletedLine",
              "lineBefore": 1,
              "content": "import { json } from '@remix-run/node'"
            },
            {
              "type": "DeletedLine",
              "lineBefore": 2,
              "content": ""
            },
            {
              "type": "DeletedLine",
              "lineBefore": 3,
              "content": "export async function loader() {"
            },
            {
              "type": "DeletedLine",
              "lineBefore": 4,
              "content": "\treturn json({ iAm: 'deleted' })"
            },
            {
              "type": "DeletedLine",
              "lineBefore": 5,
              "content": "}"
            }
          ]
        }
      ],
      "path": "var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.problem.outlet/xn2ci7n8yna/app/routes/deleted.tsx"
    },
    {
      "type": "ChangedFile",
      "chunks": [
        {
          "type": "Chunk",
          "toFileRange": {
            "start": 1,
            "lines": 7
          },
          "fromFileRange": {
            "start": 1,
            "lines": 12
          },
          "changes": [
            {
              "type": "DeletedLine",
              "lineBefore": 1,
              "content": "import { Link } from '@remix-run/react'"
            },
            {
              "type": "DeletedLine",
              "lineBefore": 2,
              "content": ""
            },
            {
              "type": "UnchangedLine",
              "lineBefore": 3,
              "lineAfter": 1,
              "content": "export default function Index() {"
            },
            {
              "type": "UnchangedLine",
              "lineBefore": 4,
              "lineAfter": 2,
              "content": "\treturn ("
            },
            {
              "type": "DeletedLine",
              "lineBefore": 5,
              "content": "\t\t<main className=\"relative min-h-screen bg-white\">"
            },
            {
              "type": "AddedLine",
              "lineAfter": 3,
              "content": "\t\t<main className=\"relative min-h-screen bg-white sm:flex sm:items-center sm:justify-center\">"
            },
            {
              "type": "UnchangedLine",
              "lineBefore": 6,
              "lineAfter": 4,
              "content": "\t\t\t<h1>Welcome to the app</h1>"
            },
            {
              "type": "DeletedLine",
              "lineBefore": 7,
              "content": "\t\t\t<Link to=\"/whatever\" className=\"text-blue-800 underline\">"
            },
            {
              "type": "DeletedLine",
              "lineBefore": 8,
              "content": "\t\t\t\tGo to \"/whatever\""
            },
            {
              "type": "DeletedLine",
              "lineBefore": 9,
              "content": "\t\t\t</Link>"
            },
            {
              "type": "UnchangedLine",
              "lineBefore": 10,
              "lineAfter": 5,
              "content": "\t\t</main>"
            },
            {
              "type": "UnchangedLine",
              "lineBefore": 11,
              "lineAfter": 6,
              "content": "\t)"
            },
            {
              "type": "UnchangedLine",
              "lineBefore": 12,
              "lineAfter": 7,
              "content": "}"
            }
          ]
        }
      ],
      "path": "var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.solution.outlet/xn2ci7n8yna/app/routes/index.tsx"
    },
    {
      "type": "AddedFile",
      "chunks": [
        {
          "type": "Chunk",
          "toFileRange": {
            "start": 1,
            "lines": 3
          },
          "fromFileRange": {
            "start": 0,
            "lines": 0
          },
          "changes": [
            {
              "type": "AddedLine",
              "lineAfter": 1,
              "content": "export default function Parent() {"
            },
            {
              "type": "AddedLine",
              "lineAfter": 2,
              "content": "\treturn <p>I am a parent</p>"
            },
            {
              "type": "AddedLine",
              "lineAfter": 3,
              "content": "}"
            }
          ]
        }
      ],
      "path": "var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.solution.outlet/xn2ci7n8yna/app/routes/parent.tsx"
    },
    {
      "type": "ChangedFile",
      "chunks": [
        {
          "type": "Chunk",
          "toFileRange": {
            "start": 1,
            "lines": 14
          },
          "fromFileRange": {
            "start": 1,
            "lines": 19
          },
          "changes": [
            {
              "type": "UnchangedLine",
              "lineBefore": 1,
              "lineAfter": 1,
              "content": "{"
            },
            {
              "type": "DeletedLine",
              "lineBefore": 2,
              "content": "  \"name\": \"exercises.01.nested-routing.01.problem.outlet\","
            },
            {
              "type": "AddedLine",
              "lineAfter": 2,
              "content": "  \"name\": \"exercises.01.nested-routing.01.solution.outlet\","
            },
            {
              "type": "UnchangedLine",
              "lineBefore": 3,
              "lineAfter": 3,
              "content": "  \"private\": true,"
            },
            {
              "type": "UnchangedLine",
              "lineBefore": 4,
              "lineAfter": 4,
              "content": "  \"sideEffects\": false,"
            },
            {
              "type": "DeletedLine",
              "lineBefore": 5,
              "content": "  \"kcd-workshop\": {"
            },
            {
              "type": "DeletedLine",
              "lineBefore": 6,
              "content": "    \"testRequiresApp\": true,"
            },
            {
              "type": "DeletedLine",
              "lineBefore": 7,
              "content": "    \"scripts\": {"
            },
            {
              "type": "DeletedLine",
              "lineBefore": 8,
              "content": "      \"test\": \"echo \\\"\\\\x1b[36mhello\\\\x1b[37mworld\\\" && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi && sleep 0.7 && echo hi\""
            },
            {
              "type": "DeletedLine",
              "lineBefore": 9,
              "content": "    }"
            },
            {
              "type": "DeletedLine",
              "lineBefore": 10,
              "content": "  },"
            },
            {
              "type": "UnchangedLine",
              "lineBefore": 11,
              "lineAfter": 5,
              "content": "  \"type\": \"module\","
            },
            {
              "type": "UnchangedLine",
              "lineBefore": 12,
              "lineAfter": 6,
              "content": "  \"scripts\": {"
            },
            {
              "type": "UnchangedLine",
              "lineBefore": 13,
              "lineAfter": 7,
              "content": "    \"build\": \"run-s build:*\","
            },
            {
              "type": "UnchangedLine",
              "lineBefore": 14,
              "lineAfter": 8,
              "content": "    \"build:remix\": \"remix build\","
            },
            {
              "type": "UnchangedLine",
              "lineBefore": 15,
              "lineAfter": 9,
              "content": "    \"build:server\": \"tsx ./other/build-server.ts\","
            },
            {
              "type": "UnchangedLine",
              "lineBefore": 16,
              "lineAfter": 10,
              "content": "    \"dev\": \"remix dev -c \\\"tsx ./index.js\\\" --manual\","
            },
            {
              "type": "AddedLine",
              "lineAfter": 11,
              "content": "    \"test\": \"echo TODO\","
            },
            {
              "type": "UnchangedLine",
              "lineBefore": 17,
              "lineAfter": 12,
              "content": "    \"format\": \"prettier --write .\","
            },
            {
              "type": "UnchangedLine",
              "lineBefore": 18,
              "lineAfter": 13,
              "content": "    \"lint\": \"eslint --cache --cache-location ./node_modules/.cache/eslint .\","
            },
            {
              "type": "UnchangedLine",
              "lineBefore": 19,
              "lineAfter": 14,
              "content": "    \"start\": \"cross-env NODE_ENV=production node .\","
            }
          ]
        }
      ],
      "path": "var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/example/exercises__sep__01.nested-routing__sep__01.solution.outlet/xn2ci7n8yna/package.json"
    }
  ]
}
kentcdodds commented 1 year ago

That works great! Thank you šŸ‘šŸ‘