Skip to content

TreeEntry#path should return a posix path #1433

@mojavelinux

Description

@mojavelinux

When I use git ls-tree, regardless of whether I'm on Linux, macOS, or Windows, it always reports posix paths (paths that use forward slash as the directory separator). This makes sense since git is a database of virtual paths which have nothing to do with the filesystem / platform I'm currently on. nodegit, on the other hand, returns platform-specific paths. In other words, on Windows, the TreeEntry#path returns a different value than on Linux. It's even stranger that I request an entry using a posix path, but I get back a platform-specific path.

Here's a sample of what git ls-tree -r HEAD returns on Windows:

100644 blob 3fda23c7b550d75eae3d62e471dd35bbc3d6e667    guides/README.md
100644 blob 7a44d0cf690215933974035542d5af6280294982    guides/cloning/README.md
100644 blob 1a9190ab32758755dc1b964e157d2a44abc512d5    guides/cloning/gh-two-factor/README.md
100644 blob d723e52ccf3569b4b25f25ee5d5f21b7a4138453    guides/cloning/gh-two-factor/index.js
100644 blob f6b7c7a3700b1f29bb40b4a9df01795e3a46f106    guides/cloning/index.js

Here are the paths nodegit returns on Windows when walking the same tree:

guides\README.md
guides\cloning\README.md
guides\cloning\gh-two-factor\README.md
guides\cloning\gh-two-factor\index.js
guides\cloning\index.js

This problem can be easily resolved by using path.posix instead of path in tree_entry.js (and perhaps other places).

If the user really wants the Windows-variant of the path, they can easily get it by passing the value to path.normalize.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions