git-newline-at-eof 0.1.0 → 0.1.1
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/README.md +23 -6
- data/lib/git-newline-at-eof.rb +74 -14
- data/lib/git-newline-at-eof/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a01c1b70f05acc4a310172b58b8d7e5671512ab
|
4
|
+
data.tar.gz: b142b16ed809608cefa7cd1c6cf2d8c4424e9452
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7767f8d52eca61f9e31736f7d00d1b9e3274a567da7d9569dc965eddfcbdc3891b84568eea6348426f123df39990ef34c93a7847295a6444359244a36cc63b61
|
7
|
+
data.tar.gz: 833f844b2f87af807efb00f4953e89aaa6dbd3b0620c3138a065c4c6b9e6e117ca21dbf329ac79dfee2e2b019e014f098abebd42bdd17a947eea01bd4c102ea4
|
data/README.md
CHANGED
@@ -57,6 +57,8 @@ $ git commit -m "Fix last line terminator"
|
|
57
57
|
1 file changed, 1 insertion(+), 1 deletion(-)
|
58
58
|
```
|
59
59
|
|
60
|
+
Zero byte file has zero newline for termination because it has zero line.
|
61
|
+
|
60
62
|
### `--discard-last-newline`
|
61
63
|
|
62
64
|
Remove discarded newline at end of file.
|
@@ -105,22 +107,37 @@ $ mkdir /tmp/test
|
|
105
107
|
$ cd /tmp/test
|
106
108
|
$ printf "" > file0
|
107
109
|
$ printf "aaa" > file1
|
108
|
-
$ printf "bbb\n
|
109
|
-
$ printf "ccc\n\n
|
110
|
+
$ printf "bbb\n" > file2
|
111
|
+
$ printf "ccc\n\n" > file3
|
112
|
+
$ printf "ddd\n\n\n" > file4
|
110
113
|
$ git init
|
111
114
|
Initialized empty Git repository in /tmp/test/.git/
|
112
115
|
$ git add .
|
113
116
|
$ git commit -m "Initial commit"
|
114
|
-
[master (root-commit)
|
115
|
-
|
117
|
+
[master (root-commit) 0806035] Initial commit
|
118
|
+
5 files changed, 7 insertions(+)
|
116
119
|
create mode 100644 file0
|
117
120
|
create mode 100644 file1
|
118
121
|
create mode 100644 file2
|
119
122
|
create mode 100644 file3
|
123
|
+
create mode 100644 file4
|
120
124
|
$ git newline-at-eof --check-all
|
121
125
|
file1: no newline at end of file
|
122
|
-
|
123
|
-
|
126
|
+
file3: discarded 1 newline at end of file
|
127
|
+
file4: discarded 2 newlines at end of file
|
128
|
+
```
|
129
|
+
|
130
|
+
### `--help`
|
131
|
+
|
132
|
+
Help.
|
133
|
+
|
134
|
+
```bash
|
135
|
+
$ git newline-at-eof --help
|
136
|
+
Usage: git-newline-at-eof [options]
|
137
|
+
-f, --feed-last-line Add newline to line what is not terminated by newline at end of file.
|
138
|
+
-d, --discard-last-newline Remove discarded newline at end of file.
|
139
|
+
-a, --treat-all This is identical with --feed-last-line --discard-last-newline.
|
140
|
+
-c, --check-all Check and show warning about newline at end of file.
|
124
141
|
```
|
125
142
|
|
126
143
|
## Supported Versions
|
data/lib/git-newline-at-eof.rb
CHANGED
@@ -5,29 +5,89 @@ module GitNewlineAtEof
|
|
5
5
|
class Application
|
6
6
|
def initialize(argv)
|
7
7
|
@files = files
|
8
|
-
@
|
9
|
-
@
|
10
|
-
@
|
11
|
-
@
|
8
|
+
@options = {}
|
9
|
+
@options[:feed_last_line] = false
|
10
|
+
@options[:discard_last_newline] = false
|
11
|
+
@options[:treat_all] = false
|
12
|
+
@options[:check_all] = false
|
13
|
+
@options[:opted] = false
|
12
14
|
|
13
|
-
opt = OptionParser.new
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
@opt = OptionParser.new
|
16
|
+
[
|
17
|
+
[
|
18
|
+
'-f', '--feed-last-line',
|
19
|
+
'Add newline to line what is not terminated by newline at end of file.',
|
20
|
+
proc { |v|
|
21
|
+
@options[:feed_last_line] = true
|
22
|
+
@options[:opted] = true
|
23
|
+
}
|
24
|
+
],
|
25
|
+
[
|
26
|
+
'-d',
|
27
|
+
'--discard-last-newline',
|
28
|
+
'Remove discarded newline at end of file.',
|
29
|
+
proc { |v|
|
30
|
+
@options[:discard_last_newline] = true
|
31
|
+
@options[:opted] = true
|
32
|
+
}
|
33
|
+
],
|
34
|
+
[
|
35
|
+
'-a',
|
36
|
+
'--treat-all',
|
37
|
+
'This is identical with --feed-last-line --discard-last-newline.',
|
38
|
+
proc { |v|
|
39
|
+
@options[:treat_all] = true
|
40
|
+
@options[:opted] = true
|
41
|
+
}
|
42
|
+
],
|
43
|
+
[
|
44
|
+
'-c',
|
45
|
+
'--check-all',
|
46
|
+
'Check and show warning about newline at end of file.',
|
47
|
+
proc { |v|
|
48
|
+
@options[:check_all] = true
|
49
|
+
@options[:opted] = true
|
50
|
+
}
|
51
|
+
],
|
52
|
+
[
|
53
|
+
'-h',
|
54
|
+
'--help',
|
55
|
+
'Show this message.',
|
56
|
+
proc { |v|
|
57
|
+
puts @opt.help
|
58
|
+
@options[:opted] = true
|
59
|
+
}
|
60
|
+
],
|
61
|
+
[
|
62
|
+
'-v',
|
63
|
+
'--version',
|
64
|
+
'Show version.',
|
65
|
+
proc {
|
66
|
+
@options[:opted] = true
|
67
|
+
puts @opt.ver
|
68
|
+
}
|
69
|
+
]
|
70
|
+
].each do |short, long, desc, proc_obj|
|
71
|
+
@opt.on(short, long, desc, &proc_obj)
|
72
|
+
end
|
73
|
+
@opt.program_name = 'git newline-at-eof'
|
74
|
+
@opt.version = GitNewlineAtEof::VERSION
|
75
|
+
@opt.parse!(argv)
|
19
76
|
end
|
20
77
|
|
21
78
|
def run
|
22
|
-
|
79
|
+
unless @options[:opted]
|
80
|
+
puts @opt.help
|
81
|
+
end
|
82
|
+
if @options[:check_all]
|
23
83
|
check_all
|
24
|
-
elsif @
|
84
|
+
elsif @options[:treat_all]
|
25
85
|
treat_all
|
26
86
|
else
|
27
|
-
if @
|
87
|
+
if @options[:feed_last_line]
|
28
88
|
feed_last_line_all
|
29
89
|
end
|
30
|
-
if @
|
90
|
+
if @options[:discard_last_newline]
|
31
91
|
discard_last_newline_all
|
32
92
|
end
|
33
93
|
end
|