Skip to content

Commit fd21e7d

Browse files
authored
Fix validate --diff when multiple owned globs are present (#101)
* Add spec that demonstrates the issue * Presence of file in any owned glob is good enough
1 parent 53eb92b commit fd21e7d

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/code_ownership/private.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def self.file_tracked?(file)
9292
# However, globbing out can take 5 or more seconds on a large repository, dramatically slowing down
9393
# invocations to `bin/codeownership validate --diff`.
9494
# Using `File.fnmatch?` is a lot faster!
95-
in_owned_globs = configuration.owned_globs.all? do |owned_glob|
95+
in_owned_globs = configuration.owned_globs.any? do |owned_glob|
9696
File.fnmatch?(owned_glob, file, File::FNM_PATHNAME | File::FNM_EXTGLOB)
9797
end
9898

spec/lib/code_ownership/cli_spec.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44
describe 'validate' do
55
let(:argv) { ['validate'] }
6+
let(:owned_globs) { nil }
67

78
before do
8-
write_configuration
9+
write_configuration(owned_globs: owned_globs)
910
write_file('app/services/my_file.rb')
1011
write_file('frontend/javascripts/my_file.jsx')
1112
end
@@ -21,6 +22,22 @@
2122
end
2223
end
2324

25+
context 'with --diff argument' do
26+
let(:argv) { ['validate', '--diff'] }
27+
28+
before do
29+
allow(ENV).to receive(:fetch).and_call_original
30+
allow(ENV).to receive(:fetch).with('CODEOWNERS_GIT_STAGED_FILES').and_return('app/services/my_file.rb')
31+
end
32+
33+
context 'when there are multiple owned_globs' do
34+
let(:owned_globs) { ['app/*/**', 'lib/*/**'] }
35+
36+
it 'validates the tracked file' do
37+
expect { subject }.to raise_error CodeOwnership::InvalidCodeOwnershipConfigurationError
38+
end
39+
end
40+
end
2441
end
2542

2643
describe 'for_file' do

0 commit comments

Comments
 (0)