Skip to content
Snippets Groups Projects
Verified Commit afaeb8f2 authored by Yorick Peterse's avatar Yorick Peterse
Browse files

Handle missing attribute files when parsing

Previously using Gitlab::Git::Attributes when $GIT_DIR/info/attributes
didn't exist would result in a runtime error. This commit fixes this so
an empty Hash is produced instead.
parent 7e618d03
No related branches found
No related tags found
No related merge requests found
v 10.6.1
- Fix parsing Git attributes when $GIT_DIR/info/attributes doesn't exist
v 10.6.0
- Use a pure Ruby Git attributes file parser to drastically reduce time spent in parsing Git attributes
 
Loading
Loading
Loading
Loading
@@ -86,6 +86,8 @@ module Gitlab
def each_line
full_path = File.join(@path, 'info/attributes')
 
return unless File.exist?(full_path)
File.open(full_path, 'r') do |handle|
handle.each_line do |line|
yield line.strip
Loading
Loading
Loading
Loading
@@ -59,6 +59,14 @@ describe Gitlab::Git::Attributes do
it 'ignores any comments and empty lines' do
expect(subject.patterns.length).to eq(7)
end
it 'does not parse anything when the attributes file does not exist' do
expect(File).to receive(:exist?).
with(File.join(path, 'info/attributes')).
and_return(false)
expect(subject.patterns).to eq({})
end
end
 
describe '#parse_attributes' do
Loading
Loading
@@ -93,5 +101,13 @@ describe Gitlab::Git::Attributes do
 
expect { |b| subject.each_line(&b) }.to yield_successive_args(*args)
end
it 'does not yield when the attributes file does not exist' do
expect(File).to receive(:exist?).
with(File.join(path, 'info/attributes')).
and_return(false)
expect { |b| subject.each_line(&b) }.not_to yield_control
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment