Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ g.remove('file.txt', :cached => true) # git rm -f --cached -- "file.txt"
g.commit('message')
g.commit_all('message')

# Sign a commit using the gpg key configured in the user.signingkey config setting
g.config('user.signingkey', '0A46826A')
g.commit('message', gpg_sign: true)

# Sign a commit using a specified gpg key
key_id = '0A46826A'
g.commit('message', gpg_sign: key_id)

g = Git.clone(repo, 'myrepo')
g.chdir do
new_file('test-file', 'blahblahblah')
Expand Down
9 changes: 8 additions & 1 deletion lib/git/lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,14 @@ 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]
arr_opts << '--gpg-sign' if opts[:gpg_sign] == true || "--gpg-sign=#{opts[:gpg_sign]}" if opts[:gpg_sign]
if opts[:gpg_sign]
arr_opts <<
if opts[:gpg_sign] == true
'--gpg-sign'
else
"--gpg-sign=#{opts[:gpg_sign]}"
end
end

command('commit', arr_opts)
end
Expand Down
37 changes: 37 additions & 0 deletions tests/units/test_commit_with_gpg.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env ruby

require File.dirname(__FILE__) + '/../test_helper'

class TestCommitWithGPG < Test::Unit::TestCase
def setup
set_file_paths
end

def test_with_configured_gpg_keyid
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: true)
assert_match(/commit.*--gpg-sign['"]/, actual_cmd)
end
end

def test_with_specific_gpg_keyid
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: 'keykeykey')
assert_match(/commit.*--gpg-sign=keykeykey['"]/, actual_cmd)
end
end
end