Skip to content

Parse old mode and new mode lines properly #11

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@
break simiLoop;

case 'deleted':
case 'old':
case 'new':
var leftStr = simiLine.slice(spaceIndex + 1);
if (leftStr.indexOf('file mode') === 0) {
currentInfo[infoType === 'new' ? 'newMode' : 'oldMode'] = leftStr.slice(10);
var match = / mode (\d+)/.exec(simiLine);
if (match) {
currentInfo[infoType === 'new' ? 'newMode' : 'oldMode'] = match[1];
}
break;

Expand Down
10 changes: 10 additions & 0 deletions test/git.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ describe("git specific tests", () => {
expect(file.newMode).toBe('100644');
});

it("should have old and new modes", () => {
const diff = parse("chmod.diff");
const file = diff[0];
expect(file.type).toBe("modify");
expect(file.oldPath).toBe("a.txt");
expect(file.newPath).toBe("a.txt");
expect(file.oldMode).toBe('100644');
expect(file.newMode).toBe('100755');
});

it("should parse filename correctly if whitespace included", () => {
const diff = parse("edit-ws.diff");
const file = diff[0];
Expand Down
9 changes: 9 additions & 0 deletions test/git/chmod.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
diff --git a/a.txt b/a.txt
old mode 100644
new mode 100755
index 7898192..7e8a165
--- a/a.txt
+++ b/a.txt
@@ -1 +1,2 @@
a
+a