gitattributes 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +57 -2
- data/gitattributes.gemspec +1 -1
- data/lib/reality/git/attribute_rule.rb +1 -1
- data/lib/reality/git/attributes.rb +14 -2
- data/test/reality/git/test_attribute_rule.rb +1 -1
- data/test/reality/git/test_attributes.rb +17 -4
- 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: f2759e748dc351ded9388399184c90221e585fa4
|
4
|
+
data.tar.gz: e0806187ce98ed16a53d968ab396509c0d4b796c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c97e8f630ef87a46056c906f655004c3ac15bbf5dd93e4e51eb3a2eb1f07ee8714935e881d7ff805e2b9f5ac8c7ed124af08e73229afa844f30ca6862fdedc36
|
7
|
+
data.tar.gz: a7163bb1a24119ebe960bbd902146b922da59bee50417259a139f8175d188e518f4cfa654bea741bdd8da4aea245a7115194b2b552336ede42cb2497e16834bf
|
data/README.md
CHANGED
@@ -6,7 +6,62 @@ Classes to parse `.gitattributes` files.
|
|
6
6
|
|
7
7
|
A simple example of it's usage:
|
8
8
|
|
9
|
+
### Read an existing .gitattributes
|
10
|
+
|
11
|
+
Read an existing file that looks like
|
12
|
+
|
13
|
+
```
|
14
|
+
README.md text eol=lf
|
15
|
+
*.jpg binary
|
16
|
+
```
|
17
|
+
|
18
|
+
With code that looks like
|
19
|
+
|
9
20
|
```ruby
|
10
|
-
|
11
|
-
|
21
|
+
require 'reality/gitattributes'
|
22
|
+
|
23
|
+
attributes = Reality::Git::Attributes.parse('/home/user/myrepo')
|
24
|
+
attributes.attributes('README.md') # => { "text" => true, "eol" => "lf }
|
25
|
+
attributes.attributes('*.jpg') # => { "binary" => true }
|
26
|
+
```
|
27
|
+
|
28
|
+
### Write .gitattributes
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
require 'reality/gitattributes'
|
32
|
+
|
33
|
+
attributes = Reality::Git::Attributes.new('/home/user/myrepo')
|
34
|
+
attributes.dos_text_rule('*.cmd')
|
35
|
+
attributes.dos_text_rule('*.rdl', :eofnl => false)
|
36
|
+
attributes.unix_text_rule('*.sh')
|
37
|
+
attributes.text_rule('*.md')
|
38
|
+
attributes.binary_rule('*.jpg')
|
39
|
+
|
40
|
+
attributes.write_to('/home/user/myrepo/.gitattributes')
|
41
|
+
```
|
42
|
+
|
43
|
+
produces a file that looks like
|
44
|
+
|
45
|
+
```
|
46
|
+
*.cmd text eol=crlf
|
47
|
+
*.rdl text eol=crlf -eofnl
|
48
|
+
*.sh text eol=lf
|
49
|
+
*.md text
|
50
|
+
*.jpg binary
|
51
|
+
```
|
52
|
+
|
53
|
+
You could also pass `:prefix` and `:normalize` options to write_to method like
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
attributes.write_to('/home/user/myrepo/.gitattributes', :normalize => true, :prefix => '# DO NOT EDIT: File is auto-generated')
|
57
|
+
```
|
58
|
+
|
59
|
+
to produce a file that looks like:
|
60
|
+
|
61
|
+
```
|
62
|
+
# DO NOT EDIT: File is auto-generated
|
63
|
+
*.cmd text eol=crlf
|
64
|
+
*.md text
|
65
|
+
*.rdl text eol=crlf -eofnl
|
66
|
+
*.sh text eol=lf
|
12
67
|
```
|
data/gitattributes.gemspec
CHANGED
@@ -16,7 +16,7 @@ module Reality #nodoc
|
|
16
16
|
module Git
|
17
17
|
# Represents a rule within the attributes file
|
18
18
|
class AttributeRule
|
19
|
-
ATTR_ORDER = %w(text
|
19
|
+
ATTR_ORDER = %w(text binary eol encoding eofnl)
|
20
20
|
|
21
21
|
def initialize(pattern, attributes)
|
22
22
|
@pattern = pattern
|
@@ -61,12 +61,24 @@ module Reality #nodoc
|
|
61
61
|
@rules << AttributeRule.new(pattern, attributes)
|
62
62
|
end
|
63
63
|
|
64
|
+
# Adds a rule for pattern that sets the text attribute.
|
65
|
+
# This means that the file will be stored in the repository with line endings converted to LF
|
64
66
|
def text_rule(pattern, attributes = {})
|
65
|
-
rule(pattern, { :text => true
|
67
|
+
rule(pattern, { :text => true }.merge(attributes))
|
66
68
|
end
|
67
69
|
|
70
|
+
# Adds a rule for pattern that sets the text attribute and eol=lf.
|
71
|
+
# This means that the file will be stored in the repository with line endings converted to LF
|
72
|
+
# *and* the local checkout will have line endings converted to LF
|
73
|
+
def unix_text_rule(pattern, attributes = {})
|
74
|
+
text_rule(pattern, { :eol => 'lf' }.merge(attributes))
|
75
|
+
end
|
76
|
+
|
77
|
+
# Adds a rule for pattern that sets the text attribute and eol=crlf.
|
78
|
+
# This means that the file will be stored in the repository with line endings converted to LF
|
79
|
+
# *and* the local checkout will have line endings converted to CRLF
|
68
80
|
def dos_text_rule(pattern, attributes = {})
|
69
|
-
text_rule(pattern, { :
|
81
|
+
text_rule(pattern, { :eol => 'crlf' }.merge(attributes))
|
70
82
|
end
|
71
83
|
|
72
84
|
def binary_rule(pattern, attributes = {})
|
@@ -32,7 +32,7 @@ class Reality::Git::TestAttributeRule < Reality::TestCase
|
|
32
32
|
def test_many_attributes
|
33
33
|
rule = Reality::Git::AttributeRule.new('*.rdl', 'eofnl' => false, 'text' => true, 'crlf' => true, 'binary' => false, 'ms-file' => 'RPT', 'age' => '22')
|
34
34
|
assert_equal({ 'eofnl' => false, 'text' => true, 'crlf' => true, 'binary' => false, 'ms-file' => 'RPT', 'age' => '22' }, rule.attributes)
|
35
|
-
assert_equal('*.rdl text
|
35
|
+
assert_equal('*.rdl text -binary -eofnl age=22 crlf ms-file=RPT', rule.to_s)
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_sorting
|
@@ -53,7 +53,7 @@ TEXT
|
|
53
53
|
write_standard_file(dir, content)
|
54
54
|
|
55
55
|
attributes = Reality::Git::Attributes.parse(dir)
|
56
|
-
assert_equal(['*.textile text -
|
56
|
+
assert_equal(['*.textile text -binary -crlf'], attributes.rules.collect {|p| p.to_s})
|
57
57
|
|
58
58
|
assert_equal({}, attributes.attributes('README.md'))
|
59
59
|
assert_equal({ 'text' => true, 'crlf' => false, 'binary' => false }, attributes.attributes('README.textile'))
|
@@ -69,7 +69,7 @@ TEXT
|
|
69
69
|
write_standard_file(dir, content)
|
70
70
|
|
71
71
|
attributes = Reality::Git::Attributes.parse(dir)
|
72
|
-
assert_equal(['* -text', '*.textile text -
|
72
|
+
assert_equal(['* -text', '*.textile text -binary -crlf'], attributes.rules.collect {|p| p.to_s})
|
73
73
|
|
74
74
|
assert_equal({ 'text' => false }, attributes.attributes('README.md'))
|
75
75
|
assert_equal({ 'text' => true, 'crlf' => false, 'binary' => false }, attributes.attributes('doc/X.textile'))
|
@@ -241,7 +241,20 @@ TEXT
|
|
241
241
|
attributes.text_rule('*.md')
|
242
242
|
attributes.text_rule('*.rake', :eofnl => false)
|
243
243
|
|
244
|
-
assert_equal(['*.md text
|
244
|
+
assert_equal(['*.md text', '*.rake text -eofnl'], attributes.rules.collect {|p| p.to_s})
|
245
|
+
end
|
246
|
+
|
247
|
+
def test_add_unix_text_rule
|
248
|
+
dir = "#{working_dir}/#{::SecureRandom.hex}"
|
249
|
+
|
250
|
+
attributes = Reality::Git::Attributes.new(dir)
|
251
|
+
|
252
|
+
assert_equal([], attributes.rules.collect {|p| p.to_s})
|
253
|
+
|
254
|
+
attributes.unix_text_rule('*.sh')
|
255
|
+
attributes.unix_text_rule('*.init', :eofnl => false)
|
256
|
+
|
257
|
+
assert_equal(['*.sh text eol=lf', '*.init text eol=lf -eofnl'], attributes.rules.collect {|p| p.to_s})
|
245
258
|
end
|
246
259
|
|
247
260
|
def test_add_dos_text_rule
|
@@ -254,7 +267,7 @@ TEXT
|
|
254
267
|
attributes.dos_text_rule('*.cmd')
|
255
268
|
attributes.dos_text_rule('*.rdl', :eofnl => false)
|
256
269
|
|
257
|
-
assert_equal(['*.cmd text crlf
|
270
|
+
assert_equal(['*.cmd text eol=crlf', '*.rdl text eol=crlf -eofnl'], attributes.rules.collect {|p| p.to_s})
|
258
271
|
end
|
259
272
|
|
260
273
|
def test_add_binary_rule
|
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.2.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-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|