Skip to content

Commit 19f3386

Browse files
committed
Make :no_gpg_sign its own option
1 parent 049b379 commit 19f3386

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

lib/git/lib.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,8 @@ def remove(path = '.', opts = {})
647647
# :date
648648
# :no_verify
649649
# :allow_empty_message
650-
# :gpg_sign (accepts true, false, or a gpg key ID as a String)
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,15 +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.has_key?(: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'
668-
elsif opts[:gpg_sign] == false
669-
'--no-gpg-sign'
670672
else
671673
"--gpg-sign=#{opts[:gpg_sign]}"
672674
end
675+
elsif opts[:no_gpg_sign]
676+
arr_opts << '--no-gpg-sign'
673677
end
674678

675679
command('commit', arr_opts)

tests/units/test_commit_with_gpg.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,19 @@ def test_disabling_gpg_sign
4444
`true`
4545
end
4646
message = 'My commit message'
47-
git.commit(message, gpg_sign: false)
47+
git.commit(message, no_gpg_sign: true)
4848
assert_match(/commit.*--no-gpg-sign['"]/, actual_cmd)
4949
end
5050
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
5162
end

0 commit comments

Comments
 (0)