gitattributes 2.4.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/gitattributes.gemspec +1 -1
- data/lib/reality/git/attributes.rb +24 -3
- data/test/reality/git/test_attributes.rb +24 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b782ca7bbdcc120c34494e2db3887dcf25d7a9fa
|
4
|
+
data.tar.gz: 02120c50fa900d5893c20964c6e931b228ef97e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b441a8a54c939961406cbb9307ce6e00ca9d7124ee003d2428a358a315257c005176f19b4f519296fb74c9875229b2d65628c67cd08c5d21a7078ca8f5cd938
|
7
|
+
data.tar.gz: ec1bd6314c6296a962fc140f6d0587da069292ba019f9280178aeae8473832e5cc6351c6ceb1d396f8e71ee77926b6151dc3a0d3499c3c7bb6b4aabd72e8fc25
|
data/gitattributes.gemspec
CHANGED
@@ -34,6 +34,10 @@ module Reality #nodoc
|
|
34
34
|
@attributes_file = attributes_file || "#{@path}/.gitattributes"
|
35
35
|
@relative_path = relative_path || File.dirname(@attributes_file)
|
36
36
|
@rules = rules
|
37
|
+
@rule_map = {}
|
38
|
+
rules.each do |rule|
|
39
|
+
cache_rule(rule)
|
40
|
+
end
|
37
41
|
end
|
38
42
|
|
39
43
|
attr_reader :attributes_file
|
@@ -42,7 +46,7 @@ module Reality #nodoc
|
|
42
46
|
def attributes(path)
|
43
47
|
full_path = File.join(@path, path)
|
44
48
|
|
45
|
-
|
49
|
+
self.rules.reverse.each do |rule|
|
46
50
|
full_pattern = rule.pattern[0] == '/' ? "#{@relative_path}#{rule.pattern}" : "#{@relative_path}/**/#{rule.pattern}"
|
47
51
|
return rule.attributes if File.fnmatch?(full_pattern, full_path, File::FNM_PATHNAME | File::FNM_DOTMATCH)
|
48
52
|
end
|
@@ -52,14 +56,17 @@ module Reality #nodoc
|
|
52
56
|
|
53
57
|
def write_to(filename, options = {})
|
54
58
|
prefix = options[:prefix].nil? ? '' : "#{options[:prefix]}\n"
|
55
|
-
rules =
|
59
|
+
rules = self.rules
|
60
|
+
rules = rules.dup.sort.uniq if options[:normalize]
|
56
61
|
content = rules.collect {|r| r.to_s}.join("\n")
|
57
62
|
content += "\n" unless content.empty?
|
58
63
|
IO.write(filename, prefix + content)
|
59
64
|
end
|
60
65
|
|
61
66
|
def rule(pattern, attributes)
|
62
|
-
|
67
|
+
rule = AttributeRule.new(pattern, attributes)
|
68
|
+
@rules << rule
|
69
|
+
cache_rule(rule)
|
63
70
|
end
|
64
71
|
|
65
72
|
# Adds a rule for pattern that sets the text attribute.
|
@@ -90,6 +97,20 @@ module Reality #nodoc
|
|
90
97
|
def rules
|
91
98
|
@rules.dup
|
92
99
|
end
|
100
|
+
|
101
|
+
def rules_by_pattern(pattern)
|
102
|
+
@rule_map[pattern].nil? ? [] : @rule_map[pattern].dup
|
103
|
+
end
|
104
|
+
|
105
|
+
def rules_by_pattern?(pattern)
|
106
|
+
!rules_by_pattern(pattern).empty?
|
107
|
+
end
|
108
|
+
|
109
|
+
private
|
110
|
+
|
111
|
+
def cache_rule(rule)
|
112
|
+
(@rule_map[rule.pattern] ||= []) << rule
|
113
|
+
end
|
93
114
|
end
|
94
115
|
end
|
95
116
|
end
|
@@ -27,6 +27,24 @@ TEXT
|
|
27
27
|
assert_equal(['* -text'], attributes.rules.collect {|p| p.to_s})
|
28
28
|
|
29
29
|
assert_equal({ 'text' => false }, attributes.attributes('README.md'))
|
30
|
+
assert_equal(['* -text'], attributes.rules_by_pattern('*').collect {|p| p.to_s})
|
31
|
+
assert_equal(true, attributes.rules_by_pattern?('*'))
|
32
|
+
assert_equal(false, attributes.rules_by_pattern?('XXX'))
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_multiple_rules_with_same_pattern
|
36
|
+
content = <<TEXT
|
37
|
+
* -text
|
38
|
+
* binary
|
39
|
+
TEXT
|
40
|
+
dir = "#{working_dir}/#{::SecureRandom.hex}"
|
41
|
+
write_standard_file(dir, content)
|
42
|
+
|
43
|
+
attributes = Reality::Git::Attributes.parse(dir)
|
44
|
+
assert_equal("#{dir}/.gitattributes", attributes.attributes_file)
|
45
|
+
assert_equal(['* -text', '* binary -diff'], attributes.rules_by_pattern('*').collect {|p| p.to_s})
|
46
|
+
assert_equal(true, attributes.rules_by_pattern?('*'))
|
47
|
+
assert_equal(false, attributes.rules_by_pattern?('XXX'))
|
30
48
|
end
|
31
49
|
|
32
50
|
def test_space_pattern_in_rule
|
@@ -41,6 +59,9 @@ TEXT
|
|
41
59
|
assert_equal(['Read[[:space:]]Me.txt text crlf'], attributes.rules.collect {|p| p.to_s})
|
42
60
|
|
43
61
|
assert_equal({ 'text' => true, 'crlf' => true }, attributes.attributes('Read Me.txt'))
|
62
|
+
assert_equal(['Read[[:space:]]Me.txt text crlf'], attributes.rules_by_pattern('Read Me.txt').collect {|p| p.to_s})
|
63
|
+
assert_equal(true, attributes.rules_by_pattern?('Read Me.txt'))
|
64
|
+
assert_equal(false, attributes.rules_by_pattern?('XXX'))
|
44
65
|
end
|
45
66
|
|
46
67
|
def test_exact_match_in_subdirectory
|
@@ -70,6 +91,9 @@ TEXT
|
|
70
91
|
|
71
92
|
assert_equal({ 'text' => true }, attributes.attributes('bin/doc/README.md'))
|
72
93
|
assert_equal({ }, attributes.attributes('not/matching/bin/doc/README.md'))
|
94
|
+
assert_equal(['/bin/doc/README.md text'], attributes.rules_by_pattern('/bin/doc/README.md').collect {|p| p.to_s})
|
95
|
+
assert_equal(true, attributes.rules_by_pattern?('/bin/doc/README.md'))
|
96
|
+
assert_equal(false, attributes.rules_by_pattern?('XXX'))
|
73
97
|
end
|
74
98
|
|
75
99
|
def test_gitattributes_in_non_standard_location
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitattributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Donald
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|