codeowners icon indicating copy to clipboard operation
codeowners copied to clipboard

Respect .gitignore

Open neiser opened this issue 2 years ago • 4 comments

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?

neiser avatar Nov 18 '22 13:11 neiser

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.

hmarr avatar Nov 22 '22 17:11 hmarr

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.

rwese avatar Jul 19 '24 07:07 rwese

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.

vikstrous2 avatar Jul 23 '24 18:07 vikstrous2

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.

ti-mo avatar Jul 24 '24 09:07 ti-mo