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

Respect gitignore files from parent directories #107

Closed
wants to merge 3 commits into from

Conversation

dflupu
Copy link

@dflupu dflupu commented Jan 24, 2019

Fixes #86

@wavebeem
Copy link

wavebeem commented Apr 6, 2019

I just came here to work on this issue and here's a PR already! This would really help out my jsx-info project.

@sindresorhus
Copy link
Owner

sindresorhus commented Jan 6, 2020

@dflupu Hey, sorry. I totally missed this PR... If you're still interested, would you be able to fix the merge conflict and add some more tests?

@dflupu
Copy link
Author

dflupu commented Jan 7, 2020

Sure, I'll have it fixed up in the next few days.

@dflupu dflupu force-pushed the git-repo-up branch 3 times, most recently from 8159ac0 to ac501b6 Compare January 8, 2020 15:12
@dflupu
Copy link
Author

dflupu commented Jan 8, 2020

@sindresorhus I've updated the PR. Let me know what you think.

gitignore.js Outdated
const getIsIgnoredPredecate = (ignores, cwd) => {
return p => ignores.ignores(slash(path.relative(cwd, ensureAbsolutePathForCwd(cwd, p))));
const getIsIgnoredPredecate = (ignores, gitRoot, cwd) => {
return p => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a descriptive variable name.

gitignore.js Outdated
return getIsIgnoredPredecate(ignores, options.cwd);
const {cwd} = options;

const gitDir = await findUp('.git', {cwd});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const gitDir = await findUp('.git', {cwd});
const gitDirectory = await findUp('.git', {cwd});

]);

const gitIgnoreFileContents = await Promise.all(
[].concat(...gitIgnoreFilePaths)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a TODO comment about using flatMap here when we target Node.js 12?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume we do [].concat(...gitIgnoreFilePaths) because it's nested arrays?

]);

const gitIgnoreFileContents = await Promise.all(
[].concat(...gitIgnoreFilePaths)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume we do [].concat(...gitIgnoreFilePaths) because it's nested arrays?

@sindresorhus
Copy link
Owner

The new behavior needs to be documented in the readme and index.d.ts.

And it would be good with some integrations tests that uses globby() and not gitignore().

@sindresorhus sindresorhus changed the title include gitignore files from parent dirs Adhere to gitignore files from parent directories Feb 22, 2020
@sindresorhus sindresorhus changed the title Adhere to gitignore files from parent directories Respect gitignore files from parent directories Feb 22, 2020
@sindresorhus
Copy link
Owner

I'm also concerned that this will further worsen the performance, see: #50 (comment)

@dflupu
Copy link
Author

dflupu commented Mar 8, 2020

I'm also concerned that this will further worsen the performance, see: #50 (comment)

I've done a bit of testing, and that may happen in some circumstances. Globbing small directory trees (eg <5 directories, <100 files) using the sync function may be up to 3x slower. It does however become less measurable when globbing larger directory trees.

The async function is pretty much unaffected when it comes to performance - unless there is a huge gitignore file in a parent directory.

Note that the main reason as to why the gitignore option is slow in the first place seems to be the globbing for gitignore files in subdirectories. Maybe that could be avoided in some way? How about checking for gitignore files only in directories and parent directories of files that were matched by the users' glob expression? Some kind of callback from fast-glob whenever it wants to descend into a directory that tells it whether or not it should do that could also work.

@sindresorhus
Copy link
Owner

Maybe that could be avoided in some way? How about checking for gitignore files only in directories and parent directories of files that were matched by the users' glob expression? Some kind of callback from fast-glob whenever it wants to descend into a directory that tells it whether or not it should do that could also work.

Yes, I think that would be smart.

@sindresorhus
Copy link
Owner

Some kind of callback from fast-glob whenever it wants to descend into a directory that tells it whether or not it should do that could also work.

Could you open an issue on fast-glob about this use-case? Maybe there are other things fast-glob could do to make this easier.

@sindresorhus
Copy link
Owner

@dflupu Bump

@dflupu
Copy link
Author

dflupu commented Oct 2, 2020

@sindresorhus I've opened an issue on fast-glob at some point but nothing came out of that. I've also benchmarked a few different ways of dealing with the gitignore stuff and there was no clear winner. What worked better was tied to a lot of variables such as how many files were in the project, how complex the gitignore files were and also disk/cpu speed.

@sindresorhus
Copy link
Owner

I've opened an issue on fast-glob at some point but nothing came out of that.

Can you share a link to the issue?

@sindresorhus
Copy link
Owner

How do we move forward with this PR?

@dflupu
Copy link
Author

dflupu commented Oct 22, 2020

Here's the fast-glob issue. I'll mention that I've tried using @nodelib/fs.walk as the author suggested, and I've also partially implemented the functionality requested in the issue. Neither was an all-around clear winner in terms of performance (I don't remember the exact details as it's been a while).

I see a few options for this PR:

  1. Include it under an optional flag
  2. Keep it around until the overall performance of the gitignore option is somehow improved
  3. Close it. Maybe someone else will pick up this up in the future if there's no open PR, and they'll also manage to somehow improve the performance of the gitignore option

Base automatically changed from master to main January 23, 2021 11:37
@sindresorhus
Copy link
Owner

I'm going to close as it doesn't look like something will happen with this anytime soon.

#86 (comment)

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

Successfully merging this pull request may close these issues.

Respect gitignore from above
3 participants