java - JGit: read the content of a file at a commit in a branch -


i want read content of file @ commit in branch: currently, using code read content of file @ commit ignoring branch.

    public static string readcontentoffileatcommit(string commitstr, string filename)         throws ioexception {      string content = null;     objectid lastcommitid = currentrepo.resolve(commitstr);      try (revwalk revwalk = new revwalk(currentrepo)) {         revcommit commit = revwalk.parsecommit(lastcommitid);         revtree tree = commit.gettree();          try (treewalk treewalk = new treewalk(currentrepo)) {             treewalk.addtree(tree);             treewalk.setrecursive(true);             treewalk.setfilter(pathfilter.create(filename));             if (!treewalk.next()) {                 throw new illegalstateexception("did not find expected file:" + filename);             }              objectid objectid = treewalk.getobjectid(0);             objectloader loader = currentrepo.open(objectid);             content = new string(loader.getbytes());         }          revwalk.dispose();     }      return content; } 

my goal content of file @ commit done on branch.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -