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

Attribute parser support for paths without attrs

This adds Git attribute parser support for file paths that don't contain
any attributes.
parent 78682cf7
No related branches found
No related tags found
No related merge requests found
v 10.6.6
- The Git attributes parser can now parse file paths without any attributes
v 10.6.5
- Retain file mode whenever file is renamed
 
Loading
Loading
Loading
Loading
@@ -116,7 +116,9 @@ module Gitlab
 
pattern, attrs = line.split(/\s+/, 2)
 
pairs << [File.join(@path, pattern), parse_attributes(attrs)]
parsed = attrs ? parse_attributes(attrs) : {}
pairs << [File.join(@path, pattern), parsed]
end
 
# Newer entries take precedence over older entries.
Loading
Loading
Loading
Loading
@@ -46,6 +46,10 @@ describe Gitlab::Git::Attributes do
to eq({ 'gitlab-language' => 'png' })
end
 
it 'returns an empty Hash for a defined path without attributes' do
expect(subject.attributes('bla/bla.txt')).to eq({})
end
context 'when the "binary" option is set for a path' do
it 'returns true for the "binary" option' do
expect(subject.attributes('test.binary')['binary']).to eq(true)
Loading
Loading
@@ -77,13 +81,13 @@ describe Gitlab::Git::Attributes do
it 'stores patterns in reverse order' do
first = subject.patterns.to_a[0]
 
expect(first[0]).to eq(File.join(path, '*.md'))
expect(first[0]).to eq(File.join(path, 'bla/bla.txt'))
end
 
# It's a bit hard to test for something _not_ being processed. As such we'll
# just test the number of entries.
it 'ignores any comments and empty lines' do
expect(subject.patterns.length).to eq(9)
expect(subject.patterns.length).to eq(10)
end
 
it 'does not parse anything when the attributes file does not exist' do
Loading
Loading
@@ -123,7 +127,7 @@ describe Gitlab::Git::Attributes do
 
describe '#each_line' do
it 'iterates over every line in the attributes file' do
args = [String] * 13 # the number of lines in the file
args = [String] * 14 # the number of lines in the file
 
expect { |b| subject.each_line(&b) }.to yield_successive_args(*args)
end
Loading
Loading
Loading
Loading
@@ -59,6 +59,7 @@ foo/bar.* foo
 
# This uses a tab instead of spaces to ensure the parser also supports this.
*.md\tgitlab-language=markdown
bla/bla.txt
EOF
end
end
Loading
Loading
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