Skip to content

Parse .gitignore As Git Does #466

@Kurt-von-Laven

Description

@Kurt-von-Laven

Describe the bug
.gitignore files are parsed in a manner inconsistent with their specification.

To Reproduce
Steps to reproduce the behavior:

  1. Setup a yarn 2 project using Plug'n'Play.
  2. Create a .gitignore file as recommended by yarn, optionally replacing the .yarn/* with .yarn/**.
  3. Set the "gitignore" and "blame" options to true in .jscpd.json.
  4. Install some unplugged dependencies using yarn.
  5. PnPify some SDKs using yarn pnpify --sdks.
  6. Commit your work to git.
  7. Run jscpd on the current working directory.
  8. The .yarn/sdks/ and .yarn/unplugged/ directories are searched for duplicates despite being gitignored, resulting in a "fatal: no such path" crash from git blame since these directories are not tracked.

Expected behavior
I expected the files and directories within the .yarn/ directory that were not listed in .gitignore with a leading ! to be excluded.

Desktop (please complete the following information):

  • OS: Ubuntu
  • OS Version 21.04
  • NodeJS Version 16.2.0
  • jscpd version 3.3.26

Additional context
I have not fully investigated the issue, but I observed that gitignore-to-glob filters hidden files and directories out of the gitignore file, so I recommend simply running git-check-ignore and only supporting this feature when Git is installed. Alternatively, this issue may be resolved by switching to [email protected].

Workaround
Add "./.yarn/**" to the "ignore" array in .jscpd.json.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions