File tree 3 files changed +43
-2
lines changed
3 files changed +43
-2
lines changed Original file line number Diff line number Diff line change @@ -243,6 +243,8 @@ def process_commit_log_data(data)
243
243
next
244
244
end
245
245
246
+ in_message = false if in_message && line [ 0 ..3 ] != " "
247
+
246
248
if in_message
247
249
hsh [ 'message' ] << "#{ line [ 4 ..-1 ] } \n "
248
250
next
@@ -559,9 +561,10 @@ def remove(path = '.', opts = {})
559
561
# :author
560
562
# :date
561
563
# :no_verify
564
+ # :allow_empty_message
562
565
#
563
566
# @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
565
568
def commit ( message , opts = { } )
566
569
arr_opts = [ ]
567
570
arr_opts << "--message=#{ message } " if message
@@ -571,6 +574,7 @@ def commit(message, opts = {})
571
574
arr_opts << "--author=#{ opts [ :author ] } " if opts [ :author ]
572
575
arr_opts << "--date=#{ opts [ :date ] } " if opts [ :date ] . is_a? String
573
576
arr_opts << '--no-verify' if opts [ :no_verify ]
577
+ arr_opts << '--allow-empty-message' if opts [ :allow_empty_message ]
574
578
575
579
command ( 'commit' , arr_opts )
576
580
end
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change @@ -78,5 +78,17 @@ def test_log_file_noexist
78
78
@git . log . object ( 'no-exist.txt' ) . size
79
79
end
80
80
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
82
94
end
You can’t perform that action at this time.
0 commit comments