Skip to content

Commit a46dcf2

Browse files
committed
Fix CapitalizedSubject to ignore fixup!/squash! commits
These are special commit messages created by git commands, and do not need to be marked as a problem.
1 parent fb1f02a commit a46dcf2

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* Fix `Scalastyle` pre-commit hook to capture messages with no line number
66
* Fix `CoffeeLint` pre-commit hook detection of modified lines
77
* Fix `Jscs` pre-commit hook to work with `jscs` 3.0.0+
8+
* Fix `CapitalizedSubject` pre-commit hook to ignore commit message subjects
9+
starting with `fixup!` or `squash!` special prefixes
810

911
## 0.33.0
1012

‎lib/overcommit/hook/commit_msg/capitalized_subject.rb‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@ class CapitalizedSubject < Base
44
def run
55
return :pass if empty_message?
66

7-
first_letter = commit_message_lines[0].to_s.match(/^[[:punct:]]*(.)/)[1]
8-
unless first_letter =~ /[[:upper:]]/
7+
subject = commit_message_lines[0].to_s
8+
first_letter = subject.match(/^[[:punct:]]*(.)/)[1]
9+
unless special_prefix?(subject) || first_letter =~ /[[:upper:]]/
910
return :warn, 'Subject should start with a capital letter'
1011
end
1112

1213
:pass
1314
end
15+
16+
private
17+
18+
def special_prefix?(subject)
19+
subject =~ /^(fixup|squash)!/
20+
end
1421
end
1522
end

‎spec/overcommit/hook/commit_msg/capitalized_subject_spec.rb‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,24 @@
7979

8080
it { should warn }
8181
end
82+
83+
context 'when subject starts with special "fixup!" prefix' do
84+
let(:commit_msg) { <<-MSG }
85+
fixup! commit
86+
87+
This was created by running git commit --fixup=...
88+
MSG
89+
90+
it { should pass }
91+
end
92+
93+
context 'when subject starts with special "squash!" prefix' do
94+
let(:commit_msg) { <<-MSG }
95+
squash! commit
96+
97+
This was created by running git commit --squash=...
98+
MSG
99+
100+
it { should pass }
101+
end
82102
end

0 commit comments

Comments
 (0)