0

我试图在 Ruby 中模拟以下内容: object=$1 tag_name=$2 message=$3 user_name= git config user.name user_email= git config user.email date=date +%s

tag="object ${object}
type commit
tag ${tag_name}
tagger ${user_name} <${user_email}> ${date} +0000

${message}"

echo "${tag}" | git mktag

我使用 Rugged 尝试了以下操作: repo = Rugged::Repository.new(@full_path) tag_collection = Rugged::TagCollection.new(repo) annotated_tag_sha = tag_collection.create(tag_name, sha, {:message => msg, :time => Time.now}) repo.close

然而两者并不等价。任何建议,将不胜感激。

我确实使用以下方法在本地工作:

repo = Rugged::Config.global
type = "commit"
tagname = "v99.99.2"
username = repo["user.name"]
email = repo["user.email"]
message = "this is the message for the annotated tag"
tag_contents = "object f849f9e28c7f36a826d4b451efb16516c0c3acc2\ntype #    {type}\ntag #{tagname}\ntagger #{username} <#{email}> #{Time.new.to_i}     +0000\n\n#{message}"
executecommand = "printf \"#{tag_contents}\" | git mktag"
Open3.popen3(executecommand) do |stdin, stdout, stderr, wait_thr|
exit_stats = wait_thr.value
errors = stderr.readlines
puts "Errors are #{errors}"
unless exit_stats.success?
  raise Exception, 'There was an error encountered'
end
signature_file_sha = stdout.readline.chomp
puts "signature sha is #{signature_file_sha}"

结尾

使用 git 1.9 但它现在在 git 2.0.4 中抛出错误无法验证具有 id 的对象

4

1 回答 1

0

是的你可以:

# Get the repo
repo = Rugged::Repository.open("...")

# Lookup the target object
target = repo.lookup("$object")

# Create the tag annotation object
repo.tags.create_annotation("$tag_name", target, {
  tagger: {
    name: "$user_name"
    email: "$user_email",
    time: Date.parse("$date")
  },
  message: "$message"
})

我没有对此进行测试,但这至少应该为您提供足够的指导,让您了解如何在坚固的情况下做到这一点。

于 2015-02-11T10:12:09.930 回答