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 gitignore when finding project files #1777

Closed
wants to merge 6 commits into from

Conversation

jfaz1
Copy link
Contributor

@jfaz1 jfaz1 commented Mar 1, 2025

This PR takes into account .gitignore when finding project files in git repos by default. Toggle with *respect-gitignore*.

Besides having more accurate autocomplete (e.g. ignoring .git/node_modules), project-find-file is actually usable on large projects now (e.g. autocomplete Linux kernel would take ~5 seconds to show up, now shows up instantly).

@jfaz1 jfaz1 force-pushed the project-gitignore branch from 72ed99e to 7e58599 Compare March 1, 2025 22:48
@jfaz1 jfaz1 marked this pull request as draft March 1, 2025 23:03
@jfaz1 jfaz1 marked this pull request as ready for review March 1, 2025 23:32
@jfaz1 jfaz1 force-pushed the project-gitignore branch from b828d6c to c84653c Compare March 2, 2025 23:51
@jfaz1 jfaz1 requested a review from vindarel March 2, 2025 23:57
@vindarel
Copy link
Collaborator

vindarel commented Mar 3, 2025

wait! Now this command will list all files including all node_modules/ that are normally ignored.

How are they ignored? Automatically by a call to the fdfind program. Which also respects .gitignore, .ignore (and .fdignore) by default. You didn't know about that, surely?

For a full Lisp solution, very welcome, we should ignore node_modules too :S What other big repositories should we ignore?

(defun list-project-files-git (directory)
"List all files in a git project using git ls-files."
(handler-case
(let ((cmd "git ls-files --cached --others --exclude-standard"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

this command should be tweakable -> global parameter.

@jfaz1
Copy link
Contributor Author

jfaz1 commented Mar 3, 2025

wait! Now this command will list all files including all node_modules/ that are normally ignored.

What do you mean? Won't they be ignored by git ls-files since they're in the .gitignore?

How are they ignored? Automatically by a call to the fdfind program. Which also respects .gitignore, .ignore (and .fdignore) by default. You didn't know about that, surely?

Hahh I had no idea it tried using fdfind, just found the snippet that tries. That's actually a better solution since it's more robust and not git-specific. I just didn't want to introduce another dependency but I like it a lot more. Maybe we should just throw a line in the docs mentioning it.
Edit: Nvm, found the line mentioning it. My bad 😆

Thanks! 😄

@jfaz1 jfaz1 closed this Mar 3, 2025
@jfaz1 jfaz1 deleted the project-gitignore branch March 3, 2025 15:44
@vindarel
Copy link
Collaborator

vindarel commented Mar 3, 2025

I'm sorry, I'm adding a section in the Install doc to mention it earlier.

But wait! again, because if fd isn't present the project command relies on a Lisp function that doesn't have the same behavior of ignoring files (with a slight "IIRC" prudency touch, details to be double-checked). So your code would be useful for the fallback case.

@jfaz1
Copy link
Contributor Author

jfaz1 commented Mar 3, 2025

I'm sorry, I'm adding a section in the Install doc to mention it earlier.

You're good, I'm the one that missed it 😆

But wait! again, because if fd isn't present the project command relies on a Lisp function that doesn't have the same behavior of ignoring files (with a slight "IIRC" prudency touch, details to be double-checked). So your code would be useful for the fallback case.

Yeah, if fd isn't present it uses the function that doesn't ignore them which is why I made the PR. I'm on a clean install which is why I noticed the .gitignored files showing up, I had fd in my previous setup, just didn't realize that was why. I think maybe instead of using this as a fallback, we could add fd/fd-find packages to the install instructions? It makes for a better experience in general anyways.

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.

2 participants