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

Handle non-recursive directory syntax #32

Open
mrphlip opened this issue Apr 19, 2022 · 3 comments
Open

Handle non-recursive directory syntax #32

mrphlip opened this issue Apr 19, 2022 · 3 comments

Comments

@mrphlip
Copy link

mrphlip commented Apr 19, 2022

The Github codeowners docs say:

# The `docs/*` pattern will match files like
# `docs/getting-started.md` but not further nested files like
# `docs/build-app/troubleshooting.md`.
docs/*  docs@example.com

However:

>>> from codeowners import CodeOwners
>>> owner = CodeOwners("docs/* docs@example.com")
>>> owner.of("docs/build-app/troubleshooting.md")
[('EMAIL', 'owner@example.com')]
@sbdchd
Copy link
Owner

sbdchd commented Apr 20, 2022

I think this behavior matches git's ignore behavior:

diff --git a/codeowners/test_codeowners.py b/codeowners/test_codeowners.py
index 7a9172a..def241d 100644
--- a/codeowners/test_codeowners.py
+++ b/codeowners/test_codeowners.py
@@ -479,6 +479,14 @@ GO_CODEOWNER_EXAMPLES = [
             # "bar[0-5].log": True,
         },
     ),
+    ex(
+        name="non-recursive",
+        pattern="docs/*",
+        paths={
+            "docs/getting-started.md": True,
+            "docs/build-app/troubleshooting.md": True,
+        },
+    ),
]

Passes Git's checkignore:

+ ./.venv/bin/pytest
========================================= test session starts =========================================
platform darwin -- Python 3.7.3, pytest-6.2.1, py-1.10.0, pluggy-0.13.1
rootdir: /Users/steve/projects/codeowners, configfile: tox.ini
collected 111 items                                                                                   

codeowners/test_codeowners.py ................................................................. [ 58%]
..............................................                                                  [100%]

========================================= 111 passed in 2.74s =========================================

@mrphlip
Copy link
Author

mrphlip commented Apr 20, 2022

Hmm, it does look like Github's behaviour doesn't match .gitignore for this pattern...

A .gitignore pattern that reads docs/* does cause everything in that directory to be ignored, including subdirs. But a CODEOWNERS pattern that reads docs/* only applies to files in that directory, not including subdirs.

I just spun up a test repo, I have a CODEOWNERS file that has a docs/* rule, and it does apply to files in that folder however it does not apply to files in subdirs...

@mrphlip
Copy link
Author

mrphlip commented Apr 27, 2022

For added confusion, the Git docs also say:

The pattern "foo/*", matches "foo/test.json" (a regular file), "foo/bar" (a directory), but it does not match "foo/bar/hello.c" (a regular file), as the asterisk in the pattern does not match "bar/hello.c" which has a slash in it.

However, the actual behaviour of Git does not match this:

$ cat .gitignore
foo/*
$ git check-ignore -v foo/bar/hello.c
.gitignore:1:foo/*      foo/bar/hello.c
$ git add foo/bar/hello.c
The following paths are ignored by one of your .gitignore files:
foo/bar
hint: Use -f if you really want to add them.
hint: Turn this message off by running
hint: "git config advice.addIgnoredFile false"

So it looks like Github's codeowners behaviour is matching the Git docs, but is not matching the actual Git behaviour, so trying to test this by comparing it to git check-ignore isn't going to be completely accurate.

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

No branches or pull requests

2 participants