Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JGit : How to get Branch when traversing repos

The lacking JGit docs dont seem to say anything about how to use/detect branches while using a RevWalk.

This question says pretty much the same thing.

So my question is: How do I get the branch name/id from a RevCommit? Or how do I specify which branch to traverse before hand?

like image 896
Braden Avatar asked May 03 '12 16:05

Braden


2 Answers

Found out a better way to do it by looping branches.

I looped over the branches by calling

for (Ref branch : git.branchList().call()){
    git.checkout().setName(branch.getName()).call();
    // Then just revwalk as normal.
}
like image 188
Braden Avatar answered Sep 20 '22 20:09

Braden


Looking at the current implementation of JGit (see its git repo and its RevCommit class), I didn't find the equivalent of what is listed in "Git: Finding what branch a commit came from".
Ie:

git branch --contains <commit>

Only some of the options of git branch are implemented (like in ListBranchCommand.java).

like image 36
VonC Avatar answered Sep 23 '22 20:09

VonC