Skip to content
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

The statusMatrix throw a TypeError when use in the browser with memfs #1839

Open
fengyuanchen opened this issue Nov 6, 2023 · 4 comments
Open

Comments

@fengyuanchen
Copy link

  1. Start this demo of the memfs.
  2. Append the following code after line 35 of the main.ts:
const statusMatrix = await git.statusMatrix({
  fs,
  dir: '/repo',
});
console.log('statusMatrix', statusMatrix);
  1. Open https://localhost:9876/.
  2. You will see the error in the console:
TypeError: Failed to execute 'getFileHandle' on 'FileSystemDirectoryHandle': Name is not allowed.
@fengyuanchen
Copy link
Author

fengyuanchen commented Nov 6, 2023

This error comes from line 202 of the src/api/statusMatrix.js file.

I figured out a quick solution:

const statusMatrix = await git.statusMatrix({
  fs,
  dir: '/repo',
  filter: (filepath) => filepath !== '.', // Exclude the current directory
});
console.log('statusMatrix', statusMatrix);

@jcubic
Copy link
Contributor

jcubic commented Nov 6, 2023

This is most likely an error from FsaNodeFs module you're using. If this is you're project then memfs don't follow the spec of FS for isomorphic-git. It doesn't work the same as a real NodeJS fs module or lightning-fs, they work just fine.

@jcubic
Copy link
Contributor

jcubic commented Nov 6, 2023

But also I'm wondering if the '.' is read for those FS modules that do work, which means that it will do extra work for nothing. Do you want to contribute to the code, investigate and maybe fix it (ignore '.' directory if it's read on different fs modules)?

@jcubic
Copy link
Contributor

jcubic commented Nov 6, 2023

I was checking the source code and it seems that _walk function always returns '.' as the first entry, it do that only once. I'm not sure if I can change this behavior, it will be a breaking change. Some users may rely on this behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants