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

Respect .gitignore #14

Open
neiser opened this issue Nov 18, 2022 · 5 comments · May be fixed by #32
Open

Respect .gitignore #14

neiser opened this issue Nov 18, 2022 · 5 comments · May be fixed by #32

Comments

@neiser
Copy link

neiser commented Nov 18, 2022

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
Copy link
Owner

hmarr commented Nov 22, 2022

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
Copy link

rwese commented Jul 19, 2024

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
Copy link

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 added a commit to ti-mo/codeowners that referenced this issue Jul 24, 2024
Fixes hmarr#14

This commit adds support for hiding files from output that have been excluded
by .gitignore and friends. I've implemented a few version of this and settled
on just `git ls-files` since it's likely going to be the most correct and
maintainable solution.

I've tried github.com/boyter/gocodewalker but it's a complex piece of machinery
and was much slower on a repo of 15k files (Cilium) than just git ls-files.
I also tried out github.com/ianlewis/go-gitignore directly, but it doesn't pick
up .gitignore files in subdirs automatically, nor the system-wide gitignore.

I figured since the overwhelming majority of users will be running this in CI
where Git will always be present, relying on the canonical .gitignore
implementation (git itself) is the safest option.

Signed-off-by: Timo Beckers <[email protected]>
@ti-mo ti-mo linked a pull request Jul 24, 2024 that will close this issue
@ti-mo
Copy link

ti-mo commented Jul 24, 2024

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: #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.

@landon-buttars-wgu
Copy link

Thanks for the contribution @ti-mo. Anyway you @rwese could get this reviewed?

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 a pull request may close this issue.

6 participants