Skip to content

Commit 7340bc5

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 7340bc5

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/git/lib.rb

Lines changed: 4 additions & 0 deletions
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,6 +561,7 @@ def remove(path = '.', opts = {})
559561
# :author
560562
# :date
561563
# :no_verify
564+
# :raw_opts - array of opts passed directly to command
562565
#
563566
# @param [String] message the commit message to be used
564567
# @param [Array] opts the commit options to be used
@@ -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+
opts[:raw_opts].each { |opt| arr_opts << opt } if opts.key?("raw_opts")
574578

575579
command('commit', arr_opts)
576580
end

tests/units/test_log_empty_message.rb

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

0 commit comments

Comments
 (0)