【问题标题】:"git branch --merged <sha>" via Rugged libgit2 bindings?“git branch --merged <sha>”通过 Rugged libgit2 绑定?
【发布时间】:2014-11-07 15:00:21
【问题描述】:

有什么办法可以得到和原生git命令一样的信息

git branch --merged <sha>

通过Rugged Ruby 的 libgit2 绑定?

【问题讨论】:

    标签: ruby libgit2 rugged


    【解决方案1】:

    git commit 所做的是查看每个分支并检查分支与您给出的提交(或 HEAD,如果没有)之间的合并基础是否对应于分支之一。

    如果它们匹配,则合并;如果他们不这样做,那就不是。你可以很容易地在 ruby​​ 中完成这个循环

    repo.branches.each(:local) # look only at local branches
    .map { |b|
      tgt = b.resolve.target # look at what the branch is pointing to
      # and check if the target commit is included in the history of HEAD
      merged = repo.merge_base(repo.head.target, tgt) == tgt.oid
      [b.name, merged]
    } # this will give a list with the name and whether the branch is merged
    .keep_if { |name, merged| merged } # keep only the ones which are merged
    .map(&:first) # get the name
    

    您可以在第一个块中添加一个 merged_list &lt;&lt; b.name if merged 并将其挂在 each 之外,但我喜欢编写数据流。

    您还可以根据需要更改是否对分支使用:local:remote 或两者。您还可以将 repo.head.target 更改为您想要比较的任何 id。

    【讨论】:

      猜你喜欢
      • 2013-02-13
      • 2019-10-09
      • 2019-12-25
      • 2012-10-16
      • 2021-05-09
      • 2022-12-01
      • 2013-10-18
      • 1970-01-01
      • 2018-10-18
      相关资源
      最近更新 更多