Skip to content

Commit 8743556

Browse files
committed
Add gpg_sign: false to send --no-gpg-sign to git
Signed-off-by: Bradley Buda <bradleybuda@gmail.com>
1 parent 6f2b3fd commit 8743556

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ g.commit('message', gpg_sign: true)
244244
key_id = '0A46826A'
245245
g.commit('message', gpg_sign: key_id)
246246

247+
# Skip signing a commit (overriding any global gpgsign setting)
248+
g.commit('message', gpg_sign: false)
249+
247250
g = Git.clone(repo, 'myrepo')
248251
g.chdir do
249252
new_file('test-file', 'blahblahblah')

lib/git/lib.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ def remove(path = '.', opts = {})
647647
# :date
648648
# :no_verify
649649
# :allow_empty_message
650-
# :gpg_sign
650+
# :gpg_sign (accepts true, false, or a gpg key ID as a String)
651651
#
652652
# @param [String] message the commit message to be used
653653
# @param [Hash] opts the commit options to be used
@@ -661,10 +661,12 @@ def commit(message, opts = {})
661661
arr_opts << "--date=#{opts[:date]}" if opts[:date].is_a? String
662662
arr_opts << '--no-verify' if opts[:no_verify]
663663
arr_opts << '--allow-empty-message' if opts[:allow_empty_message]
664-
if opts[:gpg_sign]
664+
if opts.has_key?(:gpg_sign)
665665
arr_opts <<
666666
if opts[:gpg_sign] == true
667667
'--gpg-sign'
668+
elsif opts[:gpg_sign] == false
669+
'--no-gpg-sign'
668670
else
669671
"--gpg-sign=#{opts[:gpg_sign]}"
670672
end

tests/units/test_commit_with_gpg.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,18 @@ 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, gpg_sign: false)
48+
assert_match(/commit.*--no-gpg-sign['"]/, actual_cmd)
49+
end
50+
end
3751
end

0 commit comments

Comments
 (0)