Skip to content

Commit 7d5fb6c

Browse files
jkoppelclaudeyeonjuan
authored
fix: handle file mode changes (old mode/new mode) in diff parsing (#41)
* fix: handle file mode changes (old mode/new mode) in diff parsing Files with `old mode`/`new mode` extended headers were not parsed correctly, causing two bugs: 1. `new mode` lines were not recognized as extended headers. The ExtendedHeader constants included `Old: 'old'` which matches `old mode ...`, but only had `NewFile: 'new file'` for new-prefixed headers. Since `'new mode ...'` does not start with `'new file'`, `parseExtendedHeader` returned null, breaking the extended header loop prematurely. 2. When `parseFileChange` returned undefined (due to unrecognized headers and no matching return conditions), `parseFileChanges` used `break` instead of `continue`, causing ALL subsequent files in the diff to be silently dropped. Fixes: - Add `NewMode: 'new mode'` to ExtendedHeader constants - Handle mode-only changes (no --- /+++ markers, no chunks) by falling back to the comparison line path - Change `parseFileChanges` to skip unparseable entries instead of aborting the entire parse Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: add changed mode data * remove console.log --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: YeonJuan <yeonjuan93@naver.com>
1 parent 9740e08 commit 7d5fb6c

22 files changed

+283
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ demo/parse-git-diff.js
1111
!.yarn/sdks
1212
!.yarn/versions
1313
playground-out
14+
.DS_Store

.yarn/install-state.gz

-335 KB
Binary file not shown.

src/__fixtures__/mode-change

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
diff --git a/script.sh b/script.sh
2+
old mode 100644
3+
new mode 100755
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
diff --git a/script.sh b/script.sh
2+
old mode 100644
3+
new mode 100755
4+
diff --git a/readme.md b/readme.md
5+
index abc1234..def5678 100644
6+
--- a/readme.md
7+
+++ b/readme.md
8+
@@ -1,3 +1,3 @@
9+
# Title
10+
-old content
11+
+new content
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
diff --git a/script.sh b/script.sh
2+
old mode 100644
3+
new mode 100755
4+
index abc1234..def5678
5+
--- a/script.sh
6+
+++ b/script.sh
7+
@@ -1,3 +1,3 @@
8+
#!/bin/bash
9+
-echo "hello"
10+
+echo "world"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
diff --git a/run.sh b/script.sh
2+
old mode 100755
3+
new mode 100644
4+
similarity index 100%
5+
rename from run.sh
6+
rename to script.sh

src/__tests__/__snapshots__/31-no-prefix.test.ts.snap

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`issue 31-no-prefix parse \`31-no-prefix\` 1`] = `
44
{
@@ -1177,6 +1177,8 @@ exports[`issue 31-no-prefix parse \`31-no-prefix\` 1`] = `
11771177
"type": "Chunk",
11781178
},
11791179
],
1180+
"newMode": undefined,
1181+
"oldMode": undefined,
11801182
"path": "var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/epicshop/diff/advanced-react-apis/09.03.solution/dn2ncwjsbmo/index.tsx",
11811183
"type": "ChangedFile",
11821184
},

src/__tests__/__snapshots__/31.test.ts.snap

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`issue 31 parse \`31\` 1`] = `
44
{
@@ -410,6 +410,8 @@ exports[`issue 31 parse \`31\` 1`] = `
410410
"type": "Chunk",
411411
},
412412
],
413+
"newMode": undefined,
414+
"oldMode": undefined,
413415
"path": "var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/epicshop/diff/advanced-react-apis/04.01.solution/7h2jowvfi2q/index.tsx",
414416
"type": "ChangedFile",
415417
},

src/__tests__/__snapshots__/all.test.ts.snap

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`aa parse \`all\` 1`] = `
44
{
@@ -31,6 +31,8 @@ exports[`aa parse \`all\` 1`] = `
3131
"type": "Chunk",
3232
},
3333
],
34+
"newMode": undefined,
35+
"oldMode": undefined,
3436
"path": "rename.md",
3537
"type": "ChangedFile",
3638
},
@@ -112,11 +114,15 @@ exports[`aa parse \`all\` 1`] = `
112114
"type": "Chunk",
113115
},
114116
],
117+
"newMode": undefined,
118+
"oldMode": undefined,
115119
"path": "rename.md",
116120
"type": "ChangedFile",
117121
},
118122
{
119123
"chunks": [],
124+
"newMode": undefined,
125+
"oldMode": undefined,
120126
"pathAfter": "rename.md",
121127
"pathBefore": "newfile.md",
122128
"type": "RenamedFile",

src/__tests__/__snapshots__/chunk-context.test.ts.snap

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`chunk-context parse \`chunk-context\` 1`] = `
44
{
@@ -31,6 +31,8 @@ exports[`chunk-context parse \`chunk-context\` 1`] = `
3131
"type": "Chunk",
3232
},
3333
],
34+
"newMode": undefined,
35+
"oldMode": undefined,
3436
"path": "rename.js",
3537
"type": "ChangedFile",
3638
},

0 commit comments

Comments
 (0)