R00t
R00t

Reputation: 186

How to get thr branch of a commit with nodegit

I'm trying to know how I can get the branch in which a commit was created in (not the head). I know a branch is just a 'tag' attached to a commit (the head of that branch)

enter image description here

For example, in this image, what would I need to do to get the branch of the node E using nodegit or another git library.

I looked in the documentation, but I didn't find an equivalent to git branch --contains

Thanks !

Upvotes: 3

Views: 676

Answers (1)

rcjsuen
rcjsuen

Reputation: 938

You'd have to:

  1. Iterate over all the branches.
  2. Find the ancestor of each branch's tip against the commit with NodeGit.Merge.base(repository, branchTip, interestedCommit).
  3. Then if the returnedCommit === interestedCommit then you're fine

Upvotes: 1

Related Questions