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

Fix attribute support for the "binary" option

When the "binary" option is set to true the "diff" option is to be set
to false automatically.
parent d47cc16e
No related branches found
No related tags found
No related merge requests found
v 10.6.3
- When parsing Git attributes "diff" is now set to false whenever "binary" is set to true
v 10.6.2
- Fix parsing Git attributes defined using an absolute path
 
Loading
Loading
Loading
Loading
@@ -57,28 +57,35 @@ module Gitlab
values = {}
dash = '-'
equal = '='
binary = 'binary'
 
string.split(/\s+/).each do |chunk|
# Data such as "foo = bar" should be treated as "foo" and "bar" being
# separate boolean attributes.
next if chunk == equal
 
key = chunk
# Input: "-foo"
if chunk.start_with?(dash)
key = chunk.byteslice(1, chunk.length - 1)
values[key] = false
value = false
 
# Input: "foo=bar"
elsif chunk.include?(equal)
key, value = chunk.split(equal, 2)
 
values[key] = value
# Input: "foo"
else
values[chunk] = true
value = true
end
values[key] = value
# When the "binary" option is set the "diff" option should be set to
# the inverse. If "diff" is later set it should overwrite the
# automatically set value.
values['diff'] = false if key == binary && value
end
 
values
Loading
Loading
Loading
Loading
@@ -45,6 +45,16 @@ describe Gitlab::Git::Attributes do
expect(subject.attributes('/foo.png')).
to eq({ 'gitlab-language' => 'png' })
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)
end
it 'returns false for the "diff" option' do
expect(subject.attributes('test.binary')['diff']).to eq(false)
end
end
end
 
context 'using a path without any attributes' do
Loading
Loading
@@ -73,7 +83,7 @@ describe Gitlab::Git::Attributes do
# 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(8)
expect(subject.patterns.length).to eq(9)
end
 
it 'does not parse anything when the attributes file does not exist' do
Loading
Loading
@@ -113,7 +123,7 @@ describe Gitlab::Git::Attributes do
 
describe '#each_line' do
it 'iterates over every line in the attributes file' do
args = [String] * 12 # the number of lines in the file
args = [String] * 13 # the number of lines in the file
 
expect { |b| subject.each_line(&b) }.to yield_successive_args(*args)
end
Loading
Loading
Loading
Loading
@@ -55,6 +55,7 @@ module SeedHelper
foo/bar.* foo
*.cgi key=value?p1=v1&p2=v2
/*.png gitlab-language=png
*.binary binary
 
# This uses a tab instead of spaces to ensure the parser also supports this.
*.md\tgitlab-language=markdown
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