Can git commit signing implementation be updated to be easier to use?

未关闭
#992 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
冷清
技术栈
git, ruby

调研方向

先阅读 Rugged::Commit.create、create_to_s 和 create_with_signature,然后跟踪对于新 bare 仓库,index.write 和引用更新的行为。完成的标准是:可以通过一次带有签名输入的 Commit 级调用创建签名 commit,同时保持 index 和 HEAD/引用的正常行为。

由索引模型根据 Issue 内容生成。

描述

Been trying to implement signing of commits in a project we use.
I have sort of gotten it to work but the implementation between a none signed commit and signed commit differs a lot and i would like it to become much easier so the code in the project i use gets cleaner.

Basically this is how we implemented none signed today, it works for a newly created bare repo also.

oid = repo.write("This is a blob.", :blob)
index = repo.index
index.read_tree(repo.head.target.tree)
index.add(:path => "README.md", :oid => oid, :mode => 0100644)

options = {}
options[:tree] = index.write_tree(repo)

options[:author] = { :email => "testuser@github.com", :name => 'Test Author', :time => Time.now }
options[:committer] = { :email => "testuser@github.com", :name => 'Test Author', :time => Time.now }
options[:message] ||= "Making a commit via Rugged!"
options[:parents] = repo.empty? ? [] : [ repo.head.target ].compact
options[:update_ref] = 'HEAD'

@commitref = Rugged::Commit.create(repo, options)

index.write

But to make signed commits in a new bare repo the first part is the same with options but alot after differs.

oid = repo.write("This is a blob.", :blob)
index = repo.index
index.read_tree(repo.head.target.tree)
index.add(:path => "README.md", :oid => oid, :mode => 0100644)

options = {}
options[:tree] = index.write_tree(repo)

options[:author] = { :email => "testuser@github.com", :name => 'Test Author', :time => Time.now }
options[:committer] = { :email => "testuser@github.com", :name => 'Test Author', :time => Time.now }
options[:message] ||= "Making a commit via Rugged!"
options[:parents] = repo.empty? ? [] : [ repo.head.target ].compact
options[:update_ref] = 'HEAD'

# Create a string of the contents to be commited.
content = Rugged::Commit.create_to_s(repo, options)

# Sign the string.
crypto = GPGME::Crypto.new(armor: true)
signature = crypto.detach_sign(content, signers: @cfg.sign_key).to_s.strip

# Create a commit using the string and signature. 
@commitref = Rugged::Commit.create_with_signature(repo, content, signature, 'gpgsig')

# After doing this create_with_signature calling for index.write does not work.
# and i have to do this repo references else i cant see any commits when i do git log --show-signature

# Check if HEAD exists and handle accordingly
if repo.references.exist?("HEAD") && !repo.head_unborn?
  # HEAD exists and points to a real branch
  repo.references.update(repo.head.name, @commitref)
else
  # HEAD doesn't exist or is unborn - create default branch
  repo.references.create("refs/heads/master", @commitref)
end

I would like the implementation of signed commits to be as easy as doing a normal commit just that i have to specify the key i want to sign with.
e.g

# Just want a function i can call for as easy as Commit.create that signs my commits and update the reference on disk. 
Rugged::Commit.commit_with_signature(repo, options, signature)
主要语言
C
星标
2.3k
派生
293
PR 合并指标
30 天内没有已合并 PR

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

libgit2/rugged 的其他 Issue

查看 libgit2/rugged 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。