fit-commit 3.0.1 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/fit-commit.gemspec +1 -1
- data/lib/fit_commit/runner.rb +16 -8
- data/lib/fit_commit/version.rb +1 -1
- data/templates/hooks/commit-msg +14 -11
- data/test/integration/new_repo_test.rb +48 -9
- data/test/unit/runner_test.rb +24 -6
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8699deb0617713906feec2843b053835d4eff93a
|
4
|
+
data.tar.gz: f7131e71ae0921ce4aaf1f6873331b008d769d1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4878977c4b1aa0aadc837053ffb3afddb63c9aeb46d6bd6bf24f78c86dab3da74cf61c41ca4e3cb3de78b8bd3d2737e19cec5e75406e5edf9c234eb2ee36c40
|
7
|
+
data.tar.gz: cac7ba464d93602fb88462dc96de993feb35ca9c5b6b0d10c69f7e4fbede134d2d35b50c81987155125d4bd1a29513687351338080d83e6a87bb258f67791cbf
|
data/CHANGELOG.md
CHANGED
data/fit-commit.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
|
|
9
9
|
gem.email = ["foley3@gmail.com"]
|
10
10
|
gem.homepage = "https://github.com/m1foley/fit-commit"
|
11
11
|
gem.summary = "A Git hook to validate your commit messages"
|
12
|
-
gem.description = "A Git hook to validate your commit messages
|
12
|
+
gem.description = "A Git hook to validate your commit messages based on community standards."
|
13
13
|
gem.files = `git ls-files`.split("\n")
|
14
14
|
gem.executables = ["fit-commit"]
|
15
15
|
gem.default_executable = "fit-commit"
|
data/lib/fit_commit/runner.rb
CHANGED
@@ -22,22 +22,30 @@ module FitCommit
|
|
22
22
|
run_validators
|
23
23
|
return EXIT_CODE_ALLOW_COMMIT if [errors, warnings].all?(&:empty?)
|
24
24
|
print_results
|
25
|
+
allow_commit = errors.empty? || ask_force_commit
|
25
26
|
|
26
|
-
allow_commit
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
if allow_commit
|
28
|
+
stderr.print "\n"
|
29
|
+
EXIT_CODE_ALLOW_COMMIT
|
30
|
+
else
|
31
|
+
EXIT_CODE_REJECT_COMMIT
|
31
32
|
end
|
32
|
-
|
33
|
-
stderr.print "\n"
|
34
|
-
allow_commit ? EXIT_CODE_ALLOW_COMMIT : EXIT_CODE_REJECT_COMMIT
|
35
33
|
rescue Interrupt # Ctrl-c
|
36
34
|
EXIT_CODE_REJECT_COMMIT
|
37
35
|
end
|
38
36
|
|
39
37
|
private
|
40
38
|
|
39
|
+
def ask_force_commit
|
40
|
+
return unless interactive?
|
41
|
+
stderr.print "\nForce commit? [y/n] "
|
42
|
+
stdin.gets =~ /y/i
|
43
|
+
end
|
44
|
+
|
45
|
+
def interactive?
|
46
|
+
stdin.tty?
|
47
|
+
end
|
48
|
+
|
41
49
|
def run_validators
|
42
50
|
validators.each do |validator|
|
43
51
|
validator.validate(lines)
|
data/lib/fit_commit/version.rb
CHANGED
data/templates/hooks/commit-msg
CHANGED
@@ -1,13 +1,4 @@
|
|
1
1
|
#!/usr/bin/env sh
|
2
|
-
#
|
3
|
-
# This hook will attempt to setup your environment before running checks.
|
4
|
-
|
5
|
-
if which rvm > /dev/null 2>&1
|
6
|
-
then cmd="rvm default do ruby"
|
7
|
-
elif which rbenv > /dev/null 2>&1
|
8
|
-
then cmd="rbenv exec ruby"
|
9
|
-
else cmd="ruby"
|
10
|
-
fi
|
11
2
|
|
12
3
|
export COMMIT_MESSAGE_PATH=$1
|
13
4
|
if [ -z "$COMMIT_MESSAGE_PATH" ]; then
|
@@ -35,7 +26,19 @@ if [ -z "$GIT_BRANCH_NAME" ]; then
|
|
35
26
|
exit 0
|
36
27
|
fi
|
37
28
|
|
38
|
-
|
29
|
+
if which rvm > /dev/null 2>&1
|
30
|
+
then cmd="rvm default do ruby"
|
31
|
+
elif which rbenv > /dev/null 2>&1
|
32
|
+
then cmd="rbenv exec ruby"
|
33
|
+
else cmd="ruby"
|
34
|
+
fi
|
35
|
+
|
36
|
+
# allow user input if running in a terminal
|
37
|
+
if [ -t 1 ]; then
|
38
|
+
exec < /dev/tty
|
39
|
+
fi
|
40
|
+
|
41
|
+
$cmd -rrubygems -e '
|
39
42
|
begin
|
40
43
|
require "fit_commit"
|
41
44
|
true
|
@@ -46,4 +49,4 @@ fit-commit: Did you set your Ruby version?
|
|
46
49
|
MESSAGE
|
47
50
|
false
|
48
51
|
end and FitCommit.run
|
49
|
-
'
|
52
|
+
'
|
@@ -5,18 +5,57 @@ require "expect"
|
|
5
5
|
describe "Install and run in a fresh Git repo" do
|
6
6
|
BINARY_PATH = File.expand_path("../../../bin/fit-commit", __FILE__)
|
7
7
|
|
8
|
-
|
8
|
+
def shell_commands(gitdir)
|
9
|
+
"cd #{gitdir} && git init && #{BINARY_PATH} install && git commit --allow-empty -m '#{commit_message}'"
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:results) do
|
13
|
+
output = ""
|
9
14
|
Dir.mktmpdir do |gitdir|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
15
|
+
PTY.spawn(shell_commands(gitdir)) do |pty_out, _pty_in, _pty_pid|
|
16
|
+
if user_input
|
17
|
+
pty_out.expect(/Force commit\?/, 3) do |expect_out|
|
18
|
+
output << Array(expect_out).join
|
19
|
+
user_input
|
20
|
+
end
|
21
|
+
else
|
22
|
+
output << pty_out.read
|
16
23
|
end
|
17
24
|
end
|
18
|
-
|
19
|
-
|
25
|
+
end
|
26
|
+
output
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "invalid commit message" do
|
30
|
+
let(:commit_message) { "fixing foo" }
|
31
|
+
let(:user_input) { "n" }
|
32
|
+
it "disallows commit" do
|
33
|
+
assert_match(/^#{commit_message}/, results)
|
34
|
+
assert_match(/^1: Error: /, results)
|
35
|
+
refute_match(/Warning:/, results)
|
36
|
+
refute_match(/^\[master .+\]/, results)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "valid commit message" do
|
41
|
+
let(:commit_message) { "Fix foo" }
|
42
|
+
let(:user_input) { nil }
|
43
|
+
it "allows commit" do
|
44
|
+
refute_match(/^#{commit_message}/, results)
|
45
|
+
refute_match(/Error:/, results)
|
46
|
+
refute_match(/Warning:/, results)
|
47
|
+
assert_match(/^\[master .+\] #{commit_message}/, results)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "commit message with warning only" do
|
52
|
+
let(:commit_message) { "X" * 51 }
|
53
|
+
let(:user_input) { nil }
|
54
|
+
it "allows commit" do
|
55
|
+
refute_match(/^#{commit_message}/, results)
|
56
|
+
refute_match(/Error/, results)
|
57
|
+
assert_match(/^1: Warning: /, results)
|
58
|
+
assert_match(/^\[master .+\] #{commit_message}/, results)
|
20
59
|
end
|
21
60
|
end
|
22
61
|
end
|
data/test/unit/runner_test.rb
CHANGED
@@ -65,31 +65,49 @@ 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
|
68
|
+
def assert_error_output(interactive: true)
|
69
69
|
stderr_lines = stderr.read.lines.map(&:chomp)
|
70
|
-
|
70
|
+
expected_lines = interactive ? 8 : 6
|
71
|
+
assert_equal expected_lines, stderr_lines.size
|
71
72
|
assert_equal commit_msg, stderr_lines[0..1].join("\n")
|
72
73
|
assert_empty stderr_lines[2]
|
73
74
|
assert_match(/\A1: Error: /, stderr_lines[3])
|
74
75
|
assert_match(/\A1: Error: /, stderr_lines[4])
|
75
76
|
assert_match(/\A2: Error: /, stderr_lines[5])
|
76
|
-
|
77
|
-
|
77
|
+
if interactive
|
78
|
+
assert_empty stderr_lines[6]
|
79
|
+
assert_equal "Force commit? [y/n] ", stderr_lines[7]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def fake_tty(text)
|
84
|
+
StringIO.new(text).tap do |stringio|
|
85
|
+
def stringio.tty?
|
86
|
+
true
|
87
|
+
end
|
88
|
+
end
|
78
89
|
end
|
79
90
|
|
80
91
|
describe "user does not force commit" do
|
81
|
-
let(:stdin) {
|
92
|
+
let(:stdin) { fake_tty("n") }
|
82
93
|
it "prints errors to stderr and rejects commit" do
|
83
94
|
assert_equal FitCommit::Runner::EXIT_CODE_REJECT_COMMIT, call_runner
|
84
95
|
assert_error_output
|
85
96
|
end
|
86
97
|
end
|
87
98
|
describe "user forces commit" do
|
88
|
-
let(:stdin) {
|
99
|
+
let(:stdin) { fake_tty("y") }
|
89
100
|
it "prints errors to stderr and allows commit" do
|
90
101
|
assert_equal FitCommit::Runner::EXIT_CODE_ALLOW_COMMIT, call_runner
|
91
102
|
assert_error_output
|
92
103
|
end
|
93
104
|
end
|
105
|
+
describe "TTY not available" do
|
106
|
+
let(:stdin) { StringIO.new("") }
|
107
|
+
it "prints errors to stderr and rejects commit" do
|
108
|
+
assert_equal FitCommit::Runner::EXIT_CODE_REJECT_COMMIT, call_runner
|
109
|
+
assert_error_output(interactive: false)
|
110
|
+
end
|
111
|
+
end
|
94
112
|
end
|
95
113
|
end
|
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.0
|
4
|
+
version: 3.1.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-09-
|
11
|
+
date: 2015-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: swearjar
|
@@ -52,8 +52,7 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '10.4'
|
55
|
-
description: A Git hook to validate your commit messages
|
56
|
-
authoritative guide.
|
55
|
+
description: A Git hook to validate your commit messages based on community standards.
|
57
56
|
email:
|
58
57
|
- foley3@gmail.com
|
59
58
|
executables:
|