hmarr / codeowners

🔒 Command line tool and Go library for CODEOWNERS files
MIT License
167 stars 19 forks source link

Respect .gitignore #14

Open neiser opened 1 year ago

neiser commented 1 year ago

When running codeowners on a typical git repository, many files are printed which are actually not part of the repository because of .gitignore. Is that correct behavior? Would you consider that to be an improvement if this tool respects (and parses?) .gitignore if present?

hmarr commented 1 year ago

Yes that sounds like a useful improvement, particularly if you can toggle that behaviour with a command line flag.

Incidentally we might be able to reuse the CODEOWNERS matching logic for the gitignore files, as CODEOWNERS patterns are based on gitignore patterns. There are a few exceptions we'd need to handle, but it'd be nice to avoid taking an extra dependency.

rwese commented 1 month ago

I'd like to work on this.

I will adapt the parser with a new Switch, like I did for sections, but will wait with adapting the cmd until the section support is merged, or further adapted to your expectations.

vikstrous2 commented 1 month ago

Another potential solution to respect gitignore: run this command to get the list of files in the repo git ls-tree -r --name-only HEAD If the codeowners tool could take the list of files as an input, the user could also do this themselves and modify the list however they want before evaluating the code ownership.

ti-mo commented 1 month ago

This has been on my backlog for a few months and finally took the time to try out a few solutions yesterday. I put up some patches here: https://github.com/hmarr/codeowners/pull/32. Looks like the library already uses rev-parse for finding the repo root, so using ls-files as a best-effort solution should be fine. Please take a look.