gliviu / dir-compare

Node JS directory compare
https://www.npmjs.com/package/dir-compare
Other
167 stars 12 forks source link

gitignoreFilter.ts does not handle symlinked paths #76

Open jcapogna opened 9 months ago

jcapogna commented 9 months ago

I implemented the gitignoreFilter as specified here https://github.com/gliviu/dir-compare?tab=readme-ov-file#implement-gitignore-filter.

However, I started getting errors like:

Error: Path /private/var/folder/a.txt is not in cwd /var/folder

(I shortened the paths for the example)

I discovered that /var/folder is actually a symlink to /private/var/folder. dir-compare turns the symlink into an absolute path, but the GlobbyFilterFunction in gitignoreFilter.ts uses the original symlinked path, not the absolute path, hence the mismatch.

I fixed this for myself by modifying line 26 of gitignoreFilter.ts to use entry.path instead of entry.absolutePath. https://github.com/gliviu/dir-compare/blob/master/test/extended/gitignoreSupport/gitignoreFilter.ts#L26

You could probably also resolve the absolute paths before calling isGitIgnoredSync.

gliviu commented 9 months ago

Thanks for suggestion. I'll take a look and update the code.