Skip to content

Commit b67a079

Browse files
authored
Merge branch 'master' into worktree
2 parents 255e8e4 + 896e31d commit b67a079

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ rvm:
44
- 2.4
55
- 2.5
66
- 2.6
7+
- 2.7
78
- ruby-head
89
- jruby
910

1011
matrix:
1112
allow_failures:
1213
- rvm: jruby
1314
- rvm: ruby-head
14-
fast_finish: true
15+
fast_finish: true

lib/git/lib.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ def process_commit_log_data(data)
243243
next
244244
end
245245

246+
in_message = false if in_message && line[0..3] != " "
247+
246248
if in_message
247249
hsh['message'] << "#{line[4..-1]}\n"
248250
next
@@ -592,9 +594,10 @@ def remove(path = '.', opts = {})
592594
# :author
593595
# :date
594596
# :no_verify
597+
# :allow_empty_message
595598
#
596599
# @param [String] message the commit message to be used
597-
# @param [Array] opts the commit options to be used
600+
# @param [Hash] opts the commit options to be used
598601
def commit(message, opts = {})
599602
arr_opts = []
600603
arr_opts << "--message=#{message}" if message
@@ -604,6 +607,7 @@ def commit(message, opts = {})
604607
arr_opts << "--author=#{opts[:author]}" if opts[:author]
605608
arr_opts << "--date=#{opts[:date]}" if opts[:date].is_a? String
606609
arr_opts << '--no-verify' if opts[:no_verify]
610+
arr_opts << '--allow-empty-message' if opts[:allow_empty_message]
607611

608612
command('commit', arr_opts)
609613
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env ruby
2+
require File.dirname(__FILE__) + '/../test_helper'
3+
4+
class TestCommitWithEmptyMessage < Test::Unit::TestCase
5+
def setup
6+
set_file_paths
7+
end
8+
9+
def test_without_allow_empty_message_option
10+
Dir.mktmpdir do |dir|
11+
git = Git.init(dir)
12+
assert_raises Git::GitExecuteError do
13+
git.commit('', { allow_empty: true })
14+
end
15+
end
16+
end
17+
18+
def test_with_allow_empty_message_option
19+
Dir.mktmpdir do |dir|
20+
git = Git.init(dir)
21+
git.commit('', { allow_empty: true, allow_empty_message: true})
22+
assert_equal(1, git.log.to_a.size)
23+
end
24+
end
25+
end

tests/units/test_log.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,17 @@ def test_log_file_noexist
7878
@git.log.object('no-exist.txt').size
7979
end
8080
end
81-
81+
82+
def test_log_with_empty_commit_message
83+
Dir.mktmpdir do |dir|
84+
git = Git.init(dir)
85+
expected_message = 'message'
86+
git.commit(expected_message, { allow_empty: true })
87+
git.commit('', { allow_empty: true, allow_empty_message: true })
88+
log = git.log
89+
assert_equal(2, log.to_a.size)
90+
assert_equal('', log[0].message)
91+
assert_equal(expected_message, log[1].message)
92+
end
93+
end
8294
end

0 commit comments

Comments
 (0)