I'm using the following code to retrieve the file from JGIT repo:
public class JGitPrintContent3
{
public static void main(String[] args) throws Exception
{
File gitWorkDir = new File("D:/jboss/server/repo/Repository/");
Git git = Git.open(gitWorkDir);
Repository repo = git.getRepository();
ObjectId lastCommitId = repo.resolve("b35fd0300270e6ba4d9238a1ab328b25a627885a");//userFile.sql
System.out.println("Points to : " + lastCommitId.name());
RevWalk revWalk = new RevWalk(repo);
RevCommit commit = revWalk.parseCommit(lastCommitId);
revWalk.markStart(commit);
RevTree tree = commit.getTree();
TreeWalk treeWalk = new TreeWalk(repo);
treeWalk.addTree(tree);
treeWalk.setRecursive(true);
treeWalk.setFilter(PathFilter.create("userFile.sql"));
ObjectId objectId = treeWalk.getObjectId(0);
System.out.println(" objectId : " + objectId );
ObjectLoader loader = repo.open(objectId);
File targetFile = new File("C:\\temp\\gittest\\target2\\" + "userFile.sql");
OutputStream out = new FileOutputStream(targetFile);
loader.copyTo(out);
out.flush();
out.close();
System.out.println("Done");
}
}
But unfortunately it is retrieving the file contents of earlier retrieved (commit Id) contents.
I would be most thankful for your help.
Thank you. ~Shyam */