File tree 4 files changed +91
-0
lines changed
lib/overcommit/hook/commit_msg
spec/overcommit/hook/commit_msg
4 files changed +91
-0
lines changed Original file line number Diff line number Diff line change 23
23
[ ruby-lint] ( https://github.com/YorickPeterse/ruby-lint )
24
24
* Add ` Jsl ` pre-commit hook that checks the style of JavaScript files with
25
25
[ JavaScript Lint] ( http://www.javascriptlint.com/ )
26
+ * Add ` CapitalizedSubject ` commit message hook
26
27
27
28
## 0.23.0
28
29
Original file line number Diff line number Diff line change @@ -22,6 +22,9 @@ CommitMsg:
22
22
requires_files : false
23
23
quiet : false
24
24
25
+ CapitalizedSubject :
26
+ description : ' Checking subject capitalization'
27
+
25
28
GerritChangeId :
26
29
enabled : false
27
30
description : ' Ensuring Gerrit Change-Id is present'
Original file line number Diff line number Diff line change
1
+ module Overcommit ::Hook ::CommitMsg
2
+ # Ensures commit message subject lines are followed by a blank line.
3
+ class CapitalizedSubject < Base
4
+ def run
5
+ first_letter = commit_message_lines [ 0 ] . to_s . match ( /^[[:punct:]]*(.)/ ) [ 1 ]
6
+ unless first_letter . match ( /[[:upper:]]/ )
7
+ return :warn , 'Subject should start with a capital letter'
8
+ end
9
+
10
+ :pass
11
+ end
12
+ end
13
+ end
Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+
3
+ describe Overcommit ::Hook ::CommitMsg ::CapitalizedSubject do
4
+ let ( :config ) { Overcommit ::ConfigurationLoader . default_configuration }
5
+ let ( :context ) { double ( 'context' ) }
6
+ subject { described_class . new ( config , context ) }
7
+
8
+ before do
9
+ subject . stub ( :commit_message_lines ) . and_return ( commit_msg . split ( "\n " ) )
10
+ end
11
+
12
+ context 'when subject starts with a capital letter' do
13
+ let ( :commit_msg ) { <<-MSG }
14
+ Initial commit
15
+
16
+ Mostly cats so far.
17
+ MSG
18
+
19
+ it { should pass }
20
+ end
21
+
22
+ context 'when subject starts with a utf-8 capital letter' do
23
+ let ( :commit_msg ) { <<-MSG }
24
+ Årsgång
25
+
26
+ Mostly cats so far.
27
+ MSG
28
+
29
+ it { should pass }
30
+ end
31
+
32
+ context 'when subject starts with punctuation and a capital letter' do
33
+ let ( :commit_msg ) { <<-MSG }
34
+ "Initial" commit
35
+
36
+ Mostly cats so far.
37
+ MSG
38
+
39
+ it { should pass }
40
+ end
41
+
42
+ context 'when subject starts with a lowercase letter' do
43
+ let ( :commit_msg ) { <<-MSG }
44
+ initial commit
45
+
46
+ I forget about commit message standards and decide to not capitalize my
47
+ subject. Still mostly cats so far.
48
+ MSG
49
+
50
+ it { should warn }
51
+ end
52
+
53
+ context 'when subject starts with a utf-8 lowercase letter' do
54
+ let ( :commit_msg ) { <<-MSG }
55
+ årsgång
56
+
57
+ I forget about commit message standards and decide to not capitalize my
58
+ subject. Still mostly cats so far.
59
+ MSG
60
+
61
+ it { should warn }
62
+ end
63
+
64
+ context 'when subject starts with punctuation and a lowercase letter' do
65
+ let ( :commit_msg ) { <<-MSG }
66
+ "initial" commit
67
+
68
+ I forget about commit message standards and decide to not capitalize my
69
+ subject. Still mostly cats so far.
70
+ MSG
71
+
72
+ it { should warn }
73
+ end
74
+ end
You can’t perform that action at this time.
0 commit comments