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

Use git2 instead of parsing .gitignore for --git-ignore #653

Merged
merged 1 commit into from
Oct 8, 2020

Conversation

ariasuni
Copy link
Collaborator

Fix #636

I can confirm that exa wasn’t able to hide a node_modules directory with a .gitignore with the line node_modules/.

Now, instead of using the glob crate to interpret the lines of .gitignore, exa uses part of the code that’s used to display the state of files in a repository.

@lucasholder
Copy link

This is also an issue in Rust projects (cargo init creates a .gitignore with a /target line). Surprised this wasn't caught earlier given it's a Rust project.

@ariasuni
Copy link
Collaborator Author

ariasuni commented May 13, 2020

For some reason, it works for directory_name but not for directory_name/. Default .gitignore created by cargo use the first syntax, while I tend to use the form with a slash at the end to indicate a folder in my own .gitignore.

Anyway, there are others cases where git patterns are different than glob patterns; it’s just much more reliable and simpler to ask git to tell us what it is ignoring.

@ogham ogham merged commit 1fe06a7 into ogham:master Oct 8, 2020
@ogham
Copy link
Owner

ogham commented Oct 8, 2020

This is fantastic! Thank you so much.

@ariasuni
Copy link
Collaborator Author

ariasuni commented Oct 8, 2020

Thanks, I’m proud of this code because I remember that it wasn’t an easy change. Glad it’s useful!

ogham added a commit that referenced this pull request Oct 13, 2020
This was an unintended consequence of #653. The Files iterator stopped using IgnoreCache and started using GitCache, which would always populated when the `--git` option was passed, without checking whether files were meant to be ignored. This meant that passing `--git` started ignoring files even without `--git-ignore`.

The solution for now is to explicitly pass the flag around, which probably should be a better type than bool but isn't. This makes the git-ignoring-related extended tests pass.
@ariasuni ariasuni deleted the fix-gitignore-option branch October 21, 2020 16:14
@Dreomite
Copy link

Dreomite commented Dec 1, 2020

I'm not sure if this is a bug or intended behavior, but .git directory is not ignored when using --git-ignore.

@ariasuni
Copy link
Collaborator Author

ariasuni commented Dec 1, 2020

Well, the current behavior is what’s documented: “ignore files mentioned in '.gitignore'.”

I guess it would make sense to not show the .git directory but people might also find this behavior unexpected. I guess it might add some complexity too, as e.g. if we hide a .git directory it has to be the one at the root of the git repository.

If someone uses --git-ignore a lot and wants this behavior, they could use an alias and add the option -I \.git. So I guess it could be changed if there is a compelling use case but otherwise I’m not sure it’s worth it.

@Dreomite
Copy link

Dreomite commented Dec 2, 2020

You're totally right. I checked my other CLI tools (fd, ripgrep, broot) and all of them behave exactly the same. I got confused because all of these tools ignore hidden files by default, and I forgot for a moment that I have my exa aliased with -a for several years.

@laoshaw
Copy link

laoshaw commented Apr 15, 2023

still node_modules is not ignored and there is no more --git-ignore option in 0.10.1 release?

@ariasuni
Copy link
Collaborator Author

ariasuni commented Sep 6, 2023

exa is unmaintained, please use the active fork eza (which has regular releases). Also see #1243

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.

--git-ignore parses paths beginning with / incorrectly
5 participants