Skip to content

Commit

Permalink
Make :no_gpg_sign its own option
Browse files Browse the repository at this point in the history
Signed-off-by: Bradley Buda <bradleybuda@gmail.com>
  • Loading branch information
bradleybuda committed Aug 18, 2022
1 parent 049b379 commit b79028f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
12 changes: 8 additions & 4 deletions lib/git/lib.rb
Expand Up @@ -647,7 +647,8 @@ def remove(path = '.', opts = {})
# :date
# :no_verify
# :allow_empty_message
# :gpg_sign (accepts true, false, or a gpg key ID as a String)
# :gpg_sign (accepts true or a gpg key ID as a String)
# :no_gpg_sign (conflicts with :gpg_sign)
#
# @param [String] message the commit message to be used
# @param [Hash] opts the commit options to be used
Expand All @@ -661,15 +662,18 @@ def commit(message, opts = {})
arr_opts << "--date=#{opts[:date]}" if opts[:date].is_a? String
arr_opts << '--no-verify' if opts[:no_verify]
arr_opts << '--allow-empty-message' if opts[:allow_empty_message]
if opts.has_key?(:gpg_sign)

if opts[:gpg_sign] && opts[:no_gpg_sign]
raise ArgumentError, 'cannot specify :gpg_sign and :no_gpg_sign'
elsif opts[:gpg_sign]
arr_opts <<
if opts[:gpg_sign] == true
'--gpg-sign'
elsif opts[:gpg_sign] == false
'--no-gpg-sign'
else
"--gpg-sign=#{opts[:gpg_sign]}"
end
elsif opts[:no_gpg_sign]
arr_opts << '--no-gpg-sign'
end

command('commit', arr_opts)
Expand Down
13 changes: 12 additions & 1 deletion tests/units/test_commit_with_gpg.rb
Expand Up @@ -44,8 +44,19 @@ def test_disabling_gpg_sign
`true`
end
message = 'My commit message'
git.commit(message, gpg_sign: false)
git.commit(message, no_gpg_sign: true)
assert_match(/commit.*--no-gpg-sign['"]/, actual_cmd)
end
end

def test_conflicting_gpg_sign_options
Dir.mktmpdir do |dir|
git = Git.init(dir)
message = 'My commit message'

assert_raises ArgumentError do
git.commit(message, gpg_sign: true, no_gpg_sign: true)
end
end
end
end

0 comments on commit b79028f

Please sign in to comment.