Skip to content

Support the commit --no-gpg-sign flag #589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add gpg_sign: false to send --no-gpg-sign to git
Signed-off-by: Bradley Buda <bradleybuda@gmail.com>
  • Loading branch information
bradleybuda committed Aug 2, 2022
commit 8743556784a13fd1242037c660ef2e912269413f
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ g.commit('message', gpg_sign: true)
key_id = '0A46826A'
g.commit('message', gpg_sign: key_id)

# Skip signing a commit (overriding any global gpgsign setting)
g.commit('message', gpg_sign: false)

g = Git.clone(repo, 'myrepo')
g.chdir do
new_file('test-file', 'blahblahblah')
Expand Down
6 changes: 4 additions & 2 deletions lib/git/lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ def remove(path = '.', opts = {})
# :date
# :no_verify
# :allow_empty_message
# :gpg_sign
# :gpg_sign (accepts true, false, or a gpg key ID as a String)
#
# @param [String] message the commit message to be used
# @param [Hash] opts the commit options to be used
Expand All @@ -661,10 +661,12 @@ 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[:gpg_sign]
if opts.has_key?(: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
Expand Down
14 changes: 14 additions & 0 deletions tests/units/test_commit_with_gpg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,18 @@ def test_with_specific_gpg_keyid
assert_match(/commit.*--gpg-sign=keykeykey['"]/, actual_cmd)
end
end

def test_disabling_gpg_sign
Dir.mktmpdir do |dir|
git = Git.init(dir)
actual_cmd = nil
git.lib.define_singleton_method(:run_command) do |git_cmd, &block|
actual_cmd = git_cmd
`true`
end
message = 'My commit message'
git.commit(message, gpg_sign: false)
assert_match(/commit.*--no-gpg-sign['"]/, actual_cmd)
end
end
end