CODEOWNERS "Last Match Wins" Not Working for Nested Directory Patterns
Summary
GitLab's CODEOWNERS file does not correctly apply the "last match wins" rule when the same directory path is defined multiple times with different owners.
Expected Behavior
According to GitLab documentation:
When a file or directory matches multiple entries in the CODEOWNERS file, the users from last pattern matching the file or directory are used.
Given a CODEOWNERS file with duplicate paths:
packages/client/docker/ @team-a
packages/client/docker/ @team-b
Files in packages/client/docker/ should be owned by @team-b (the last matching entry).
Actual Behavior
GitLab shows @team-a (the first matching entry) as the code owner, not the last one.
Steps to Reproduce
- Create a CODEOWNERS file with duplicate directory entries:
packages/client/docker/ @team-a
# ... other entries ...
packages/client/docker/ @team-b
-
View code owners for any file in
packages/client/docker/(e.g.,packages/client/docker/Dockerfile) -
Observed: GitLab shows
@team-aas the code owner -
Expected: GitLab should show
@team-bas the code owner (last match wins)
Environment
- GitLab version: 18.7 Release
Impact
This prevents implementing layered ownership patterns where multiple teams need to be involved in code reviews, with the last defined team having final approval authority. The "last match wins" rule is fundamental to CODEOWNERS functionality and is inconsistent with documented behavior.