File tree 3 files changed +36
-2
lines changed
3 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -244,6 +244,9 @@ g.commit('message', gpg_sign: true)
244
244
key_id = ' 0A46826A'
245
245
g.commit(' message' , gpg_sign: key_id)
246
246
247
+ # Skip signing a commit (overriding any global gpgsign setting)
248
+ g.commit(' message' , no_gpg_sign: true )
249
+
247
250
g = Git .clone(repo, ' myrepo' )
248
251
g.chdir do
249
252
new_file(' test-file' , ' blahblahblah' )
Original file line number Diff line number Diff line change @@ -647,7 +647,8 @@ def remove(path = '.', opts = {})
647
647
# :date
648
648
# :no_verify
649
649
# :allow_empty_message
650
- # :gpg_sign
650
+ # :gpg_sign (accepts true or a gpg key ID as a String)
651
+ # :no_gpg_sign (conflicts with :gpg_sign)
651
652
#
652
653
# @param [String] message the commit message to be used
653
654
# @param [Hash] opts the commit options to be used
@@ -661,13 +662,18 @@ def commit(message, opts = {})
661
662
arr_opts << "--date=#{ opts [ :date ] } " if opts [ :date ] . is_a? String
662
663
arr_opts << '--no-verify' if opts [ :no_verify ]
663
664
arr_opts << '--allow-empty-message' if opts [ :allow_empty_message ]
664
- if opts [ :gpg_sign ]
665
+
666
+ if opts [ :gpg_sign ] && opts [ :no_gpg_sign ]
667
+ raise ArgumentError , 'cannot specify :gpg_sign and :no_gpg_sign'
668
+ elsif opts [ :gpg_sign ]
665
669
arr_opts <<
666
670
if opts [ :gpg_sign ] == true
667
671
'--gpg-sign'
668
672
else
669
673
"--gpg-sign=#{ opts [ :gpg_sign ] } "
670
674
end
675
+ elsif opts [ :no_gpg_sign ]
676
+ arr_opts << '--no-gpg-sign'
671
677
end
672
678
673
679
command ( 'commit' , arr_opts )
Original file line number Diff line number Diff line change @@ -34,4 +34,29 @@ def test_with_specific_gpg_keyid
34
34
assert_match ( /commit.*--gpg-sign=keykeykey['"]/ , actual_cmd )
35
35
end
36
36
end
37
+
38
+ def test_disabling_gpg_sign
39
+ Dir . mktmpdir do |dir |
40
+ git = Git . init ( dir )
41
+ actual_cmd = nil
42
+ git . lib . define_singleton_method ( :run_command ) do |git_cmd , &block |
43
+ actual_cmd = git_cmd
44
+ `true`
45
+ end
46
+ message = 'My commit message'
47
+ git . commit ( message , no_gpg_sign : true )
48
+ assert_match ( /commit.*--no-gpg-sign['"]/ , actual_cmd )
49
+ end
50
+ end
51
+
52
+ def test_conflicting_gpg_sign_options
53
+ Dir . mktmpdir do |dir |
54
+ git = Git . init ( dir )
55
+ message = 'My commit message'
56
+
57
+ assert_raises ArgumentError do
58
+ git . commit ( message , gpg_sign : true , no_gpg_sign : true )
59
+ end
60
+ end
61
+ end
37
62
end
You can’t perform that action at this time.
0 commit comments