我可以使用Rugged或其他Ruby库创建孤立标记吗?

时间:2015-02-10 22:40:48

标签: ruby git tags rugged

我试图在Ruby中模拟以下内容:     对象= $ 1     TAG_NAME = $ 16     消息= $ 3     USER_NAME = git config user.name     USER_EMAIL = git config user.email     日期= 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 =&gt; msg,:time =&gt; 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为

的对象

1 个答案:

答案 0 :(得分: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"
})

我没有对此进行测试,但是这应该给你至少足够的指示如何使用坚固的。