gitattributes 2.8.0 → 2.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/gitattributes.gemspec +1 -1
- data/lib/reality/git/attribute_rule.rb +61 -1
- data/lib/reality/git/attributes.rb +14 -1
- data/lib/reality/gitattributes.rb +0 -1
- data/test/reality/git/test_attribute_rule.rb +16 -0
- metadata +1 -2
- data/lib/reality/git/attributes_parser.rb +0 -104
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74e12406eeb9e2147d5f85a1c3b3bbcec0d00413
|
4
|
+
data.tar.gz: 01349400936be63156845c7f40f527c032f127b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfa70d0473d6a1daacd5a11207b53da1e9d84b411c5f7ab4bd490338a8493e0ff70da2dfa0003b0e33b3434f727daff36aa7268686a6f23ab86179e5960268b2
|
7
|
+
data.tar.gz: f4098c940c647c8ff44ffaa4fe75caebd74228486d61a3a81334ad51a41178ea6b0cc63079b4fc110e944ca07790d52ec2bfbc745d079ed31b370a053ef0eca3
|
data/gitattributes.gemspec
CHANGED
@@ -36,7 +36,7 @@ module Reality #nodoc
|
|
36
36
|
attr_reader :priority
|
37
37
|
|
38
38
|
def to_s
|
39
|
-
rule = self.pattern.gsub(' ','[[:space:]]')
|
39
|
+
rule = self.pattern.gsub(' ', '[[:space:]]')
|
40
40
|
|
41
41
|
attributes = self.attributes.dup
|
42
42
|
ATTR_ORDER.each do |key|
|
@@ -80,6 +80,66 @@ module Reality #nodoc
|
|
80
80
|
to_s <=> other.to_s
|
81
81
|
end
|
82
82
|
end
|
83
|
+
|
84
|
+
class << self
|
85
|
+
def parse_line(line)
|
86
|
+
line = line.strip
|
87
|
+
return nil if line.start_with?('#') || line.empty?
|
88
|
+
pattern, attrs = line.strip.split(/\s+/, 2)
|
89
|
+
AttributeRule.new(pattern, attrs ? parse_attributes(attrs) : {})
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
# Parses an attribute string.
|
95
|
+
#
|
96
|
+
# These strings can be in the following formats:
|
97
|
+
#
|
98
|
+
# text # => { "text" => true }
|
99
|
+
# -text # => { "text" => false }
|
100
|
+
# key=value # => { "key" => "value" }
|
101
|
+
#
|
102
|
+
# string - The string to parse.
|
103
|
+
#
|
104
|
+
# Returns a Hash containing the attributes and their values.
|
105
|
+
def parse_attributes(string)
|
106
|
+
values = {}
|
107
|
+
dash = '-'
|
108
|
+
equal = '='
|
109
|
+
binary = 'binary'
|
110
|
+
|
111
|
+
string.split(/\s+/).each do |chunk|
|
112
|
+
# Data such as "foo = bar" should be treated as "foo" and "bar" being
|
113
|
+
# separate boolean attributes.
|
114
|
+
next if chunk == equal
|
115
|
+
|
116
|
+
key = chunk
|
117
|
+
|
118
|
+
# Input: "-foo"
|
119
|
+
if chunk.start_with?(dash)
|
120
|
+
key = chunk.byteslice(1, chunk.length - 1)
|
121
|
+
value = false
|
122
|
+
|
123
|
+
# Input: "foo=bar"
|
124
|
+
elsif chunk.include?(equal)
|
125
|
+
key, value = chunk.split(equal, 2)
|
126
|
+
|
127
|
+
# Input: "foo"
|
128
|
+
else
|
129
|
+
value = true
|
130
|
+
end
|
131
|
+
|
132
|
+
values[key] = value
|
133
|
+
|
134
|
+
# When the "binary" option is set the "diff" option should be set to
|
135
|
+
# the inverse. If "diff" is later set it should overwrite the
|
136
|
+
# automatically set value.
|
137
|
+
values['diff'] = false if key == binary && value
|
138
|
+
end
|
139
|
+
|
140
|
+
values
|
141
|
+
end
|
142
|
+
end
|
83
143
|
end
|
84
144
|
end
|
85
145
|
end
|
@@ -24,9 +24,22 @@ module Reality #nodoc
|
|
24
24
|
def parse(repository_path, attributes_file = nil, relative_path = nil)
|
25
25
|
path = File.expand_path(repository_path)
|
26
26
|
attributes_file ||= "#{path}/.gitattributes"
|
27
|
-
rules = File.exist?(attributes_file) ?
|
27
|
+
rules = File.exist?(attributes_file) ? parse_file(attributes_file) : []
|
28
28
|
Attributes.new(repository_path, attributes_file, relative_path, rules)
|
29
29
|
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def parse_file(filename)
|
34
|
+
rules = []
|
35
|
+
|
36
|
+
IO.readlines(filename).each do |line|
|
37
|
+
rule = AttributeRule.parse_line(line)
|
38
|
+
rules << rule if rule
|
39
|
+
end
|
40
|
+
|
41
|
+
rules
|
42
|
+
end
|
30
43
|
end
|
31
44
|
|
32
45
|
def initialize(repository_path, attributes_file = nil, relative_path = nil, rules = [])
|
@@ -66,4 +66,20 @@ class Reality::Git::TestAttributeRule < Reality::TestCase
|
|
66
66
|
assert_equal(false, rule1.eql?(rule2))
|
67
67
|
assert_not_equal(rule1.hash, rule2.hash)
|
68
68
|
end
|
69
|
+
|
70
|
+
def test_parse_line_comment
|
71
|
+
rule = Reality::Git::AttributeRule.parse_line('# This is a comment')
|
72
|
+
assert_equal nil, rule
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_parse_line_empty
|
76
|
+
rule = Reality::Git::AttributeRule.parse_line(' ')
|
77
|
+
assert_equal nil, rule
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_parse_line
|
81
|
+
rule = Reality::Git::AttributeRule.parse_line('*.rdl text')
|
82
|
+
assert_equal '*.rdl', rule.pattern
|
83
|
+
assert_equal({ 'text' => true }, rule.attributes)
|
84
|
+
end
|
69
85
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitattributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Donald
|
@@ -56,7 +56,6 @@ files:
|
|
56
56
|
- gitattributes.gemspec
|
57
57
|
- lib/reality/git/attribute_rule.rb
|
58
58
|
- lib/reality/git/attributes.rb
|
59
|
-
- lib/reality/git/attributes_parser.rb
|
60
59
|
- lib/reality/gitattributes.rb
|
61
60
|
- test/helper.rb
|
62
61
|
- test/reality/git/test_attribute_rule.rb
|
@@ -1,104 +0,0 @@
|
|
1
|
-
# Copyright (c) 2017 Peter Donald
|
2
|
-
# Copyright (c) 2013 Dmitriy Zaporozhets
|
3
|
-
#
|
4
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
-
# of this software and associated documentation files (the "Software"), to deal
|
6
|
-
# in the Software without restriction, including without limitation the rights
|
7
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
-
# copies of the Software, and to permit persons to whom the Software is
|
9
|
-
# furnished to do so, subject to the following conditions:
|
10
|
-
#
|
11
|
-
# The above copyright notice and this permission notice shall be included in
|
12
|
-
# all copies or substantial portions of the Software.
|
13
|
-
#
|
14
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
-
# THE SOFTWARE.
|
21
|
-
|
22
|
-
# These classes were extracted from the https://gitlab.com/ben.boeckel/gitlab_git repository
|
23
|
-
# with the gitattribtues code originally authored by Douwe Maan. Credit to the original authors.
|
24
|
-
|
25
|
-
module Reality #nodoc
|
26
|
-
module Git
|
27
|
-
# Parse the Git attribute file extracting the attributes for file patterns.
|
28
|
-
module AttributesParser
|
29
|
-
class << self
|
30
|
-
|
31
|
-
# Parses the specified Git attributes file.
|
32
|
-
def parse_file(filename)
|
33
|
-
rules = []
|
34
|
-
comment = '#'
|
35
|
-
|
36
|
-
IO.readlines(filename).each do |line|
|
37
|
-
next if line.start_with?(comment) || line.empty?
|
38
|
-
|
39
|
-
pattern, attrs = line.split(/\s+/, 2)
|
40
|
-
|
41
|
-
parsed_attributes = attrs ? parse_attributes(attrs) : {}
|
42
|
-
|
43
|
-
rules << AttributeRule.new(pattern, parsed_attributes)
|
44
|
-
end
|
45
|
-
|
46
|
-
# Newer entries take precedence over older entries.
|
47
|
-
rules
|
48
|
-
end
|
49
|
-
|
50
|
-
private
|
51
|
-
|
52
|
-
# Parses an attribute string.
|
53
|
-
#
|
54
|
-
# These strings can be in the following formats:
|
55
|
-
#
|
56
|
-
# text # => { "text" => true }
|
57
|
-
# -text # => { "text" => false }
|
58
|
-
# key=value # => { "key" => "value" }
|
59
|
-
#
|
60
|
-
# string - The string to parse.
|
61
|
-
#
|
62
|
-
# Returns a Hash containing the attributes and their values.
|
63
|
-
def parse_attributes(string)
|
64
|
-
values = {}
|
65
|
-
dash = '-'
|
66
|
-
equal = '='
|
67
|
-
binary = 'binary'
|
68
|
-
|
69
|
-
string.split(/\s+/).each do |chunk|
|
70
|
-
# Data such as "foo = bar" should be treated as "foo" and "bar" being
|
71
|
-
# separate boolean attributes.
|
72
|
-
next if chunk == equal
|
73
|
-
|
74
|
-
key = chunk
|
75
|
-
|
76
|
-
# Input: "-foo"
|
77
|
-
if chunk.start_with?(dash)
|
78
|
-
key = chunk.byteslice(1, chunk.length - 1)
|
79
|
-
value = false
|
80
|
-
|
81
|
-
# Input: "foo=bar"
|
82
|
-
elsif chunk.include?(equal)
|
83
|
-
key, value = chunk.split(equal, 2)
|
84
|
-
|
85
|
-
# Input: "foo"
|
86
|
-
else
|
87
|
-
value = true
|
88
|
-
end
|
89
|
-
|
90
|
-
values[key] = value
|
91
|
-
|
92
|
-
# When the "binary" option is set the "diff" option should be set to
|
93
|
-
# the inverse. If "diff" is later set it should overwrite the
|
94
|
-
# automatically set value.
|
95
|
-
values['diff'] = false if key == binary && value
|
96
|
-
end
|
97
|
-
|
98
|
-
values
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|