【问题标题】:Can I create an orphaned tag using Rugged or another Ruby library?我可以使用 Rugged 或其他 Ruby 库创建孤立标签吗?
【发布时间】:2015-02-10 22:40:47
【问题描述】:

我正在尝试在 Ruby 中模拟以下内容: 对象=$1 标签名=$2 消息=$3 用户名=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 => 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 的对象

【问题讨论】:

    标签: ruby git tags rugged


    【解决方案1】:

    是的,您可以:

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

    我没有对此进行测试,但这应该至少可以为您提供足够的指导,让您了解如何使用崎岖不平的方式做到这一点。

    【讨论】:

    • 谢谢亚瑟。您能否就我第一条评论中的附加代码为何不适用于 Git 2.0.4 提出任何建议?
    • 不知道。也许 git 1.9 和 2.0.4 之间发生了一些变化,但我真的怀疑情况是否如此。你确定没有别的不同吗?另外,您是否尝试过针对坚固耐用的建议解决方案?
    • 我试图通过一个从非 git 目录工作的 ide 运行代码。从命令行运行代码文件解决了这个问题。再次感谢亚瑟。
    猜你喜欢
    • 2023-04-10
    • 2014-03-17
    • 1970-01-01
    • 2014-10-10
    • 2021-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多