fit-commit 3.1.0 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +9 -0
- data/README.md +1 -1
- data/lib/fit_commit/has_errors.rb +8 -0
- data/lib/fit_commit/runner.rb +38 -7
- data/lib/fit_commit/version.rb +1 -1
- data/test/unit/runner_test.rb +61 -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: bb59c8dd8e5d52763773a9a53ccc33a1b4986ed7
|
4
|
+
data.tar.gz: 246cb45ef47a4f77e4dc24ef18c3adc824075bf9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5cd0c0d67d1eebfbe38ace9b7d7f769af567d6becd2c981489413fa2e66ceb12b4338abe5379951d67a120575af0bb86a42762176d14cebb655c5f20e9c7a64d
|
7
|
+
data.tar.gz: 7a7c003885b3dff14836482a71b065be8cfb6c36687cb9327204898132847b1ca19ab9a58f9505f07338ac0122fc41d620af7876adaab0e797cced33c68746d9
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
data/lib/fit_commit/runner.rb
CHANGED
@@ -18,11 +18,13 @@ module FitCommit
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def run
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
allow_commit = retry_on_user_edit do
|
22
|
+
return EXIT_CODE_ALLOW_COMMIT if empty_commit?
|
23
|
+
run_validators
|
24
|
+
return EXIT_CODE_ALLOW_COMMIT if [errors, warnings].all?(&:empty?)
|
25
|
+
print_results
|
26
|
+
errors.empty? || ask_force_commit
|
27
|
+
end
|
26
28
|
|
27
29
|
if allow_commit
|
28
30
|
stderr.print "\n"
|
@@ -36,10 +38,23 @@ module FitCommit
|
|
36
38
|
|
37
39
|
private
|
38
40
|
|
41
|
+
StartOverOnEditException = Class.new(StandardError)
|
42
|
+
|
43
|
+
def retry_on_user_edit
|
44
|
+
yield
|
45
|
+
rescue StartOverOnEditException
|
46
|
+
clear_lines
|
47
|
+
clear_errors
|
48
|
+
clear_warnings
|
49
|
+
edit_message && retry
|
50
|
+
end
|
51
|
+
|
39
52
|
def ask_force_commit
|
40
53
|
return unless interactive?
|
41
|
-
stderr.print "\nForce commit? [y/n] "
|
42
|
-
stdin.gets
|
54
|
+
stderr.print "\nForce commit? [y/n/e] "
|
55
|
+
input = stdin.gets
|
56
|
+
fail StartOverOnEditException if input =~ /e/i
|
57
|
+
input =~ /y/i
|
43
58
|
end
|
44
59
|
|
45
60
|
def interactive?
|
@@ -78,8 +93,24 @@ module FitCommit
|
|
78
93
|
@lines ||= FitCommit::MessageParser.new(message_path).lines
|
79
94
|
end
|
80
95
|
|
96
|
+
def clear_lines
|
97
|
+
@lines = nil
|
98
|
+
end
|
99
|
+
|
81
100
|
def empty_commit?
|
82
101
|
lines.all?(&:empty?)
|
83
102
|
end
|
103
|
+
|
104
|
+
def edit_message
|
105
|
+
system(editor, message_path)
|
106
|
+
end
|
107
|
+
|
108
|
+
DEFAULT_EDITOR = "vim"
|
109
|
+
|
110
|
+
def editor
|
111
|
+
editor = ENV["EDITOR"]
|
112
|
+
editor = DEFAULT_EDITOR unless editor && editor != "none"
|
113
|
+
editor
|
114
|
+
end
|
84
115
|
end
|
85
116
|
end
|
data/lib/fit_commit/version.rb
CHANGED
data/test/unit/runner_test.rb
CHANGED
@@ -65,10 +65,17 @@ describe FitCommit::Runner do
|
|
65
65
|
describe "commit msg contains errors" do
|
66
66
|
let(:commit_msg) { "foo.\nbar" }
|
67
67
|
|
68
|
-
def assert_error_output(interactive: true)
|
68
|
+
def assert_error_output(interactive: true, includes_edit: false)
|
69
69
|
stderr_lines = stderr.read.lines.map(&:chomp)
|
70
|
-
|
71
|
-
|
70
|
+
if interactive
|
71
|
+
if includes_edit
|
72
|
+
assert_equal 13, stderr_lines.size
|
73
|
+
else
|
74
|
+
assert_equal 8, stderr_lines.size
|
75
|
+
end
|
76
|
+
else
|
77
|
+
assert_equal 6, stderr_lines.size
|
78
|
+
end
|
72
79
|
assert_equal commit_msg, stderr_lines[0..1].join("\n")
|
73
80
|
assert_empty stderr_lines[2]
|
74
81
|
assert_match(/\A1: Error: /, stderr_lines[3])
|
@@ -76,7 +83,7 @@ describe FitCommit::Runner do
|
|
76
83
|
assert_match(/\A2: Error: /, stderr_lines[5])
|
77
84
|
if interactive
|
78
85
|
assert_empty stderr_lines[6]
|
79
|
-
|
86
|
+
assert_match(/\AForce commit\? \[y\/n\/e\] /, stderr_lines[7])
|
80
87
|
end
|
81
88
|
end
|
82
89
|
|
@@ -102,6 +109,56 @@ describe FitCommit::Runner do
|
|
102
109
|
assert_error_output
|
103
110
|
end
|
104
111
|
end
|
112
|
+
describe "user edits commit" do
|
113
|
+
let(:stdin) { fake_tty("e") }
|
114
|
+
describe "editor fails to save" do
|
115
|
+
it "rejects commit" do
|
116
|
+
def runner.edit_message
|
117
|
+
nil # fail code
|
118
|
+
end
|
119
|
+
assert_equal FitCommit::Runner::EXIT_CODE_REJECT_COMMIT, call_runner
|
120
|
+
assert_error_output
|
121
|
+
end
|
122
|
+
end
|
123
|
+
describe "edited message is valid" do
|
124
|
+
before do
|
125
|
+
def runner.edit_message
|
126
|
+
File.open(message_path, "w") do |f|
|
127
|
+
f.print "Valid message"
|
128
|
+
end
|
129
|
+
:success_code
|
130
|
+
end
|
131
|
+
end
|
132
|
+
it "allows commit" do
|
133
|
+
assert_equal FitCommit::Runner::EXIT_CODE_ALLOW_COMMIT, call_runner
|
134
|
+
assert_error_output
|
135
|
+
end
|
136
|
+
end
|
137
|
+
describe "edited message is invalid" do
|
138
|
+
before do
|
139
|
+
def runner.edit_message
|
140
|
+
File.open(message_path, "w") do |f|
|
141
|
+
f.print "invalid message."
|
142
|
+
end
|
143
|
+
:success_code
|
144
|
+
end
|
145
|
+
end
|
146
|
+
describe "user forces second commit" do
|
147
|
+
let(:stdin) { fake_tty("e\ny") }
|
148
|
+
it "asks again and accepts commit" do
|
149
|
+
assert_equal FitCommit::Runner::EXIT_CODE_ALLOW_COMMIT, call_runner
|
150
|
+
assert_error_output(includes_edit: true)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
describe "user doesn't force second commit" do
|
154
|
+
let(:stdin) { fake_tty("e\nn") }
|
155
|
+
it "asks again and rejects commit" do
|
156
|
+
assert_equal FitCommit::Runner::EXIT_CODE_REJECT_COMMIT, call_runner
|
157
|
+
assert_error_output(includes_edit: true)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
105
162
|
describe "TTY not available" do
|
106
163
|
let(:stdin) { StringIO.new("") }
|
107
164
|
it "prints errors to stderr and rejects commit" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fit-commit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Foley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: swearjar
|