Skip to content

findTreeEntry might not return existed entry if paths sorted not in lexicographical ordering #9

@nodkz

Description

@nodkz

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch @discoveryjs/scan-git@0.1.5 for the project I'm working on.

Paths might be sorted in exotic way whe "<" comparision doesn't work
eg. "communities-entry" is going earlier than "communities"
But while loop breaks earlier than can find communities entry and return null.

Here is the diff that solved my problem:

diff --git a/node_modules/@discoveryjs/scan-git/lib/tree-utils.cjs b/node_modules/@discoveryjs/scan-git/lib/tree-utils.cjs
index a6a3e39..e9d98cd 100644
--- a/node_modules/@discoveryjs/scan-git/lib/tree-utils.cjs
+++ b/node_modules/@discoveryjs/scan-git/lib/tree-utils.cjs
@@ -16,9 +16,11 @@ function findTreeEntry(buffer, path) {
             };
         }
 
-        if (path < entryPath) {
-            break;
-        }
+        // Paths might be sorted in exotic way whe "<" comparision doesn't work
+        //   eg. "communities-entry" is going earlier than "communities"
+        // if (path < entryPath) {
+        //     break;
+        // }
 
         offset = nullchar + 21;
     }

This issue body was partially generated by patch-package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions