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

Nested .gitignore breaks all ignores #578

Closed
Cammisuli opened this issue May 2, 2023 · 4 comments · Fixed by #580
Closed

Nested .gitignore breaks all ignores #578

Cammisuli opened this issue May 2, 2023 · 4 comments · Fixed by #580
Labels
bug Something's not right!

Comments

@Cammisuli
Copy link
Contributor

Cammisuli commented May 2, 2023

When using watchexec on a workspace that has folders with .gitignore files that contain * (which basically tells git to ignore this whole folder), it completely breaks ignores for the rest of the workspace.

You can clone this repro repo to see it in action:
https://github.com/Cammisuli/watch-exec-repro

Steps to reproduce:

  1. clone repo

  2. Open in vscode with rust analyzer (this just enables that files in the target/ directory is automatically changed)

  3. run watchexec --project-origin=. -- echo '$WATCHEXEC_WRITTEN_PATH'

  4. change src/main.rs (add a comment or whatever)

  5. See output

    • the expected output should be just main.rs, but we get everything in target/ as well.
  6. Stop the watchexec command

  7. Delete this-should-ignore-children/.gitignore (or change the glob to something else)

  8. run watchexec --project-origin=. -- echo '$WATCHEXEC_WRITTEN_PATH'

  9. change src/main.rs

  10. Output is only src/main.rs

  • Watchexec's version
watchexec 1.22.2 (2023-03-22) 
build-date: 2023-03-22
release: 1.22.2
features: 
  • The OS you're using
macOS 13.3.1 (22E261)

I'll try and investigate this myself and post any findings.

@Cammisuli Cammisuli added the bug Something's not right! label May 2, 2023
@Cammisuli
Copy link
Contributor Author

Cammisuli commented May 2, 2023

It looks like the GitIgnoreBuilder needs to be created for each ignore file.

let mut ignores_builder = GitignoreBuilder::new(origin);

Probably something needs to be done here instead:

let mut builder = GitignoreBuilder::new(origin);

@passcod
Copy link
Member

passcod commented May 2, 2023

Yep, this (bug and reason for it) is known, and the next priority. However, I don't have time at the moment to work on it.

@Cammisuli
Copy link
Contributor Author

I don't mind working on this if you don't have time.

If you have notes you want to share, or other pointers, I can begin fixing this.

@passcod
Copy link
Member

passcod commented May 3, 2023

Ultimately I want to replace all ignore handling, but a good start is probably to fix this particular issue, which is to use ignore properly, that is to make a gitignore instance per ignore file, and rewrite the ignore-files crate to handle both the building of that structure and the querying upon filtering. Likely a trie would be the ideal way to go but a vec or standard tree would probably work to start.

(My current understanding is that a gitignorebuilder is for a single directory; I believe that if two files apply to a single directory they can be handled by one builder. However that might be too much complexity for too little gain.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something's not right!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants