简体   繁体   English

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

[英]Can I create an orphaned tag using Rugged or another Ruby library?

I am trying to emulate the following in Ruby: object=$1 tag_name=$2 message=$3 user_name= git config user.name user_email= git config user.email date= date +%s 我试图在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

I have tried the following using 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 我已经尝试使用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

However the two are not equivalent. 然而,这两者并不相同。 Any suggestions would be appreciated. 任何建议,将不胜感激。

I did get it working locally using: 我确实使用以下方法在本地工作:

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}"

end 结束

using git 1.9 but it is throwing an error now in git 2.0.4 unable to verify object with id 使用git 1.9,但现在在git 2.0.4中抛出错误,无法验证具有id的对象

Yes, you can: 是的你可以:

# 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"
})

I did not test this, but this should give you at least enough pointers on how to do this with rugged. 我没有对此进行测试,但是这应该给你至少足够的指针,说明如何使用坚固耐用的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM