File tree Expand file tree Collapse file tree 3 files changed +36
-2
lines changed
Expand file tree Collapse file tree 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)
244244key_id = ' 0A46826A'
245245g.commit(' message' , gpg_sign: key_id)
246246
247+ # Skip signing a commit (overriding any global gpgsign setting)
248+ g.commit(' message' , no_gpg_sign: true )
249+
247250g = Git .clone(repo, ' myrepo' )
248251g.chdir do
249252new_file(' test-file' , ' blahblahblah' )
Original file line number Diff line number Diff line change @@ -647,7 +647,8 @@ def remove(path = '.', opts = {})
647647 # :date
648648 # :no_verify
649649 # :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)
651652 #
652653 # @param [String] message the commit message to be used
653654 # @param [Hash] opts the commit options to be used
@@ -661,13 +662,18 @@ def commit(message, opts = {})
661662 arr_opts << "--date=#{ opts [ :date ] } " if opts [ :date ] . is_a? String
662663 arr_opts << '--no-verify' if opts [ :no_verify ]
663664 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 ]
665669 arr_opts <<
666670 if opts [ :gpg_sign ] == true
667671 '--gpg-sign'
668672 else
669673 "--gpg-sign=#{ opts [ :gpg_sign ] } "
670674 end
675+ elsif opts [ :no_gpg_sign ]
676+ arr_opts << '--no-gpg-sign'
671677 end
672678
673679 command ( 'commit' , arr_opts )
Original file line number Diff line number Diff line change @@ -34,4 +34,29 @@ def test_with_specific_gpg_keyid
3434 assert_match ( /commit.*--gpg-sign=keykeykey['"]/ , actual_cmd )
3535 end
3636 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
3762end
You can’t perform that action at this time.
0 commit comments