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

exclude .git folder returns a null tree #71

Open
nik-lus opened this issue Nov 1, 2019 · 5 comments
Open

exclude .git folder returns a null tree #71

nik-lus opened this issue Nov 1, 2019 · 5 comments

Comments

@nik-lus
Copy link

nik-lus commented Nov 1, 2019

I'm on macOs, node v12, directory-tree v2.2.4...

When I try to create a directory tree by excluding the .git folder:

const tree = dirTree(rootPath, { exclude: [/.git/] }); console.log('tree is ', tree)

I get:

tree is null

But when I specify an absolute path to the .git folder:

const tree = dirTree(rootPath, { exclude: [/\/absolute-path-to-folder\/.git/] }); console.log('tree is ', tree)

I get:

tree is Object{...}

I'd like to exclude all .git folders (without having to specify the absolute path to them).

Has anyone else encountered this? Am I using exclude incorrectly (exclude does work as expected on any other folders starting with ' . ' just not '.git')?

@nik-lus
Copy link
Author

nik-lus commented Nov 1, 2019

Quick follow up, just tested by excluding a 'git' folder (no ' . ' prefix)

const tree = dirTree(rootPath, { exclude: [/git/] }); console.log('tree is ', tree)

and again I get:

tree is null

Is the phrase 'git' somehow a reserved word in the codebase?

@mihneadb
Copy link
Owner

Hi! What is the full path of the folder you are testing?
I think there might be a bug when the path contains what you want excluded https://github.com/mihneadb/node-directory-tree/blob/master/lib/directory-tree.js#L63.

@nik-lus
Copy link
Author

nik-lus commented Nov 10, 2019

path = '/usr/project/.git/'
excludes = [new RegExp('git')]
excludes.some((exclusion) => exclusion.test(path)); 
// from line 63: resolves to true which in turn returns null

Thanks for looking into this.

Edit: some clarification on the folder structure.
The folder looks like this:

/usr
    /project
              /.git
              /node_modules
              /x_file_1.txt
              /x_file_2.js

And I'm trying to run the directory tree on path: /usr/project

@nik-lus
Copy link
Author

nik-lus commented Nov 10, 2019

After some more thought, could it be that '.git' is the first folder in the directory and the exclusion /.git/ trips the if statement on line 63 and it returns null and never goes further in the folder?

I can exclude /node_modules/ without a problem and that works as expected.

@mihneadb
Copy link
Owner

Sorry, shouldn't path be /usr/project? It's the path of the folder you want to be represented as a tree. Might be worth creating a branch/PR with a test case. You can see how the existing stuff is laid out.

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