Skip to content

Commit 6245b56

Browse files
committedOct 22, 2015
Add GitConfig.comment_character method
Retrieve the character which git will use to indicate comments in commit message templates.
1 parent f2ab408 commit 6245b56

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed
 

‎lib/overcommit.rb

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
require 'overcommit/hook/base'
1111
require 'overcommit/hook_context/base'
1212
require 'overcommit/hook_context'
13+
require 'overcommit/git_config'
1314
require 'overcommit/git_repo'
1415
require 'overcommit/hook_signer'
1516
require 'overcommit/hook_loader/base'

‎lib/overcommit/git_config.rb

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module Overcommit
2+
# Get configuration options from git
3+
module GitConfig
4+
module_function
5+
6+
def comment_character
7+
char = `git config --get core.commentchar`.chomp
8+
char = '#' if char == ''
9+
char
10+
end
11+
end
12+
end

‎spec/overcommit/git_config_spec.rb

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require 'spec_helper'
2+
3+
describe Overcommit::GitConfig do
4+
describe '.comment_character' do
5+
subject { described_class.comment_character }
6+
7+
context 'with no configuration' do
8+
it 'should be "#"' do
9+
repo do
10+
`git config --local core.commentchar ''`
11+
expect(subject).to eq '#'
12+
end
13+
end
14+
end
15+
16+
context 'with custom configuration' do
17+
it 'should be the configured character' do
18+
repo do
19+
`git config --local core.commentchar x`
20+
expect(subject).to eq 'x'
21+
end
22+
end
23+
end
24+
end
25+
end

0 commit comments

Comments
 (0)