Skip to content

Commit daa5445

Browse files
committed
Fix detecting of commit message in Git::Lib::process_commit_log_data
If the commit doesn't contain a message, parsing the output of "git log" results in an error, which occures because the end of the commit message can't be detected. Signed-off-by: Pavel Kuznetsov <kpd200081@yandex.ru>
1 parent 4bef5ab commit daa5445

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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
@@ -559,9 +561,10 @@ def remove(path = '.', opts = {})
559561
# :author
560562
# :date
561563
# :no_verify
564+
# :allow_empty_message
562565
#
563566
# @param [String] message the commit message to be used
564-
# @param [Array] opts the commit options to be used
567+
# @param [Hash] opts the commit options to be used
565568
def commit(message, opts = {})
566569
arr_opts = []
567570
arr_opts << "--message=#{message}" if message
@@ -571,6 +574,7 @@ def commit(message, opts = {})
571574
arr_opts << "--author=#{opts[:author]}" if opts[:author]
572575
arr_opts << "--date=#{opts[:date]}" if opts[:date].is_a? String
573576
arr_opts << '--no-verify' if opts[:no_verify]
577+
arr_opts << '--allow-empty-message' if opts[:allow_empty_message]
574578

575579
command('commit', arr_opts)
576580
end

tests/units/test_log_empty_message.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env ruby
2+
require File.dirname(__FILE__) + '/../test_helper'
3+
4+
class TestLogEmptyMessage < Test::Unit::TestCase
5+
def setup
6+
set_file_paths
7+
end
8+
9+
def test_repo_with_empty_commit_message
10+
@git = Git.init(Dir.mktmpdir)
11+
opts = {}
12+
opts[:allow_empty] = true
13+
@git.commit("test", opts)
14+
opts[:allow_empty_message] = true
15+
@git.commit("", opts)
16+
assert_equal(2, @git.log.to_a.size)
17+
end
18+
end

0 commit comments

Comments
 (0)