fit-commit 3.8.2 → 3.8.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/fit_commit/message_parser.rb +3 -3
- data/lib/fit_commit/runner.rb +2 -3
- data/lib/fit_commit/validators/line_length.rb +20 -16
- data/lib/fit_commit/version.rb +1 -1
- data/test/integration/new_repo_test.rb +1 -1
- data/test/unit/runner_test.rb +1 -1
- data/test/unit/validators/capitalize_subject_test.rb +0 -8
- data/test/unit/validators/line_length_test.rb +16 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d208481fa7e6d24b87d13377174a9bf8cd24cb9216be8419af43de28fc95a743
|
4
|
+
data.tar.gz: 9bd15f6e38177245dc717eb8e47765b97802c67c4767ad520af784c32e1d22fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f77e6d5d22b3e5f5ccb77da1cb6e6dc0a7806ca47ae515866ce113fd0296ed6d9d90eaffea727bcb8139bdc062f89b4aa2ce1319df321c10db15e670a4806c92
|
7
|
+
data.tar.gz: 1fa6486fddcc4dde6553955f28fa25379225198667e1f574a1c571c842ff5d31b254fd889202cf9ae6bf20621dcadf770966738ccc93a9d392eb4e1ac6006feb
|
data/README.md
CHANGED
@@ -2,6 +2,9 @@ require "fit_commit/line"
|
|
2
2
|
|
3
3
|
module FitCommit
|
4
4
|
class MessageParser
|
5
|
+
GIT_VERBOSE_MARKER = "# ------------------------ >8 ------------------------"
|
6
|
+
COMMENT_REGEX = /\A#/
|
7
|
+
|
5
8
|
attr_accessor :message_path
|
6
9
|
def initialize(message_path)
|
7
10
|
self.message_path = message_path
|
@@ -13,9 +16,6 @@ module FitCommit
|
|
13
16
|
|
14
17
|
private
|
15
18
|
|
16
|
-
GIT_VERBOSE_MARKER = "# ------------------------ >8 ------------------------"
|
17
|
-
COMMENT_REGEX = /\A#/
|
18
|
-
|
19
19
|
def relevant_lines
|
20
20
|
message_text.lines.each_with_object([]) do |line, relevant_lines|
|
21
21
|
line.chomp!
|
data/lib/fit_commit/runner.rb
CHANGED
@@ -8,6 +8,7 @@ module FitCommit
|
|
8
8
|
|
9
9
|
EXIT_CODE_ALLOW_COMMIT = 0
|
10
10
|
EXIT_CODE_REJECT_COMMIT = 1
|
11
|
+
DEFAULT_EDITOR = "vim"
|
11
12
|
|
12
13
|
attr_accessor :message_path, :branch_name, :stderr, :stdin
|
13
14
|
def initialize(message_path, branch_name, stderr = $stderr, stdin = $stdin)
|
@@ -51,7 +52,7 @@ module FitCommit
|
|
51
52
|
|
52
53
|
def ask_force_commit
|
53
54
|
return unless interactive?
|
54
|
-
stderr.print "\
|
55
|
+
stderr.print "\nCommit anyway? [y/n/e] "
|
55
56
|
input = stdin.gets
|
56
57
|
fail StartOverOnEditException if input =~ /e/i
|
57
58
|
input =~ /y/i
|
@@ -105,8 +106,6 @@ module FitCommit
|
|
105
106
|
system(editor, message_path)
|
106
107
|
end
|
107
108
|
|
108
|
-
DEFAULT_EDITOR = "vim"
|
109
|
-
|
110
109
|
def editor
|
111
110
|
editor = ENV["EDITOR"]
|
112
111
|
editor = DEFAULT_EDITOR unless editor && editor != "none"
|
@@ -3,28 +3,32 @@ require "fit_commit/validators/base"
|
|
3
3
|
module FitCommit
|
4
4
|
module Validators
|
5
5
|
class LineLength < Base
|
6
|
+
MERGE_COMMIT = /\AMerge branch '[^']+' into ./
|
7
|
+
URL = %r{[a-z]+://}
|
8
|
+
|
6
9
|
def validate_line(lineno, text)
|
7
|
-
if lineno == 1
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
if lineno == 1
|
11
|
+
if text.empty?
|
12
|
+
add_error(lineno, "Subject line cannot be blank.")
|
13
|
+
elsif text !~ MERGE_COMMIT
|
14
|
+
if text.length > max_line_length
|
15
|
+
add_error(lineno, format("Lines should be <= %i chars. (%i)",
|
16
|
+
max_line_length, text.length))
|
17
|
+
elsif text.length > subject_warn_length
|
18
|
+
add_warning(lineno, format("Subject line should be <= %i chars. (%i)",
|
19
|
+
subject_warn_length, text.length))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
elsif lineno == 2
|
23
|
+
unless text.empty?
|
24
|
+
add_error(lineno, "Second line must be blank.")
|
25
|
+
end
|
26
|
+
elsif text.length > max_line_length && !(allow_long_urls? && text =~ URL)
|
12
27
|
add_error(lineno, format("Lines should be <= %i chars. (%i)",
|
13
28
|
max_line_length, text.length))
|
14
|
-
elsif lineno == 1 && text.length > subject_warn_length
|
15
|
-
add_warning(lineno, format("Subject line should be <= %i chars. (%i)",
|
16
|
-
subject_warn_length, text.length))
|
17
29
|
end
|
18
30
|
end
|
19
31
|
|
20
|
-
def line_too_long?(text)
|
21
|
-
text.length > max_line_length && !(allow_long_urls? && contains_url?(text))
|
22
|
-
end
|
23
|
-
|
24
|
-
def contains_url?(text)
|
25
|
-
text =~ %r{[a-z]+://}
|
26
|
-
end
|
27
|
-
|
28
32
|
def max_line_length
|
29
33
|
config.fetch("MaxLineLength")
|
30
34
|
end
|
data/lib/fit_commit/version.rb
CHANGED
@@ -14,7 +14,7 @@ describe "Install and run in a fresh Git repo" do
|
|
14
14
|
Dir.mktmpdir do |gitdir|
|
15
15
|
PTY.spawn(shell_commands(gitdir)) do |pty_out, _pty_in, _pty_pid|
|
16
16
|
if user_input
|
17
|
-
pty_out.expect(/
|
17
|
+
pty_out.expect(/Commit anyway\?/, 3) do |expect_out|
|
18
18
|
output << Array(expect_out).join
|
19
19
|
user_input
|
20
20
|
end
|
data/test/unit/runner_test.rb
CHANGED
@@ -74,7 +74,7 @@ describe FitCommit::Runner do
|
|
74
74
|
assert_match(/\A2: Error: /, stderr_lines[5])
|
75
75
|
if interactive
|
76
76
|
assert_empty stderr_lines[6]
|
77
|
-
assert_match(/\
|
77
|
+
assert_match(/\ACommit anyway\? \[y\/n\/e\] /, stderr_lines[7])
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
@@ -37,14 +37,6 @@ describe FitCommit::Validators::CapitalizeSubject do
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
40
|
-
describe "test " do
|
41
|
-
let(:commit_msg) { "\nsdf" }
|
42
|
-
it "has a warning" do
|
43
|
-
validator.validate(commit_lines)
|
44
|
-
assert_empty validator.errors
|
45
|
-
assert_empty validator.warnings
|
46
|
-
end
|
47
|
-
end
|
48
40
|
describe "subject is a single uncapitalized word with a body" do
|
49
41
|
let(:commit_msg) { "foo\n\nbaz" }
|
50
42
|
it "has error" do
|
@@ -42,6 +42,22 @@ describe FitCommit::Validators::LineLength do
|
|
42
42
|
assert_empty validator.warnings
|
43
43
|
end
|
44
44
|
end
|
45
|
+
describe "first line is over error limit and has an URL" do
|
46
|
+
let(:commit_msg) { "foo https://" + ("x" * 70) }
|
47
|
+
it "has an error and no warning" do
|
48
|
+
validator.validate(commit_lines)
|
49
|
+
assert_equal 1, validator.errors[1].size
|
50
|
+
assert_empty validator.warnings
|
51
|
+
end
|
52
|
+
end
|
53
|
+
describe "merge commit is over error limit" do
|
54
|
+
let(:commit_msg) { "Merge branch '#{"x" * 30}' into #{"y" * 30}" }
|
55
|
+
it "does not have error" do
|
56
|
+
validator.validate(commit_lines)
|
57
|
+
assert_empty validator.errors
|
58
|
+
assert_empty validator.warnings
|
59
|
+
end
|
60
|
+
end
|
45
61
|
describe "SubjectWarnLength modified in config" do
|
46
62
|
let(:config) { default_config.merge("SubjectWarnLength" => 5) }
|
47
63
|
describe "first line is over modified warning limit" 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.8.
|
4
|
+
version: 3.8.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Foley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: swearjar
|
@@ -130,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0'
|
132
132
|
requirements: []
|
133
|
-
rubygems_version: 3.
|
133
|
+
rubygems_version: 3.4.13
|
134
134
|
signing_key:
|
135
135
|
specification_version: 4
|
136
136
|
summary: A Git hook to validate your commit messages
|