jlewi / hydros

hydros automates hydrating and committing configuration
Apache License 2.0
4 stars 0 forks source link

hydros doesn't respect .gitignore in sub directories #23

Open jlewi opened 1 year ago

jlewi commented 1 year ago

I have a project with the following directory tree

.gitignore
frontend/.gitignore

Here frontend is a flutter app. When hydros automatically commits all files. It ends up picking up files from frontend that should be ignored by frontend/.gitignore

jlewi commented 1 year ago

Root issue is that go-git ignores .gitignore https://github.com/go-git/go-git/issues/597

We use the workaround suggested here https://github.com/go-git/go-git/issues/597#issuecomment-1301637889

Here's the code https://github.com/jlewi/hydros/blob/2034660a805aa8152a75a10f5edebb7502791799/pkg/gitutil/gitutil.go#L44

Which doesn't work with nested .gitingore

I think we could extend it to work with nested .gitignores as follows

We could probably simplify it as follows; in walking the directory to find .gitignore it would probably be sufficient to just ignore hidden directories (directories that start with "."). This way we wouldn't need logic to match directories against git exclude patterns (although I imagine there are functions in gogit or elsewhere we could use).