我需要在JGit中打印已提交文件的状态,无论是添加,删除,更改等等。为此我最初克隆了远程存储库,并获得了提交ID,作者姓名,作者邮件ID,日期和时间。但是当我尝试使用IndexDiff / Status类打印状态时,我得到空值。
我需要知道是否可以在有或没有克隆的情况下获取已提交文件在远程存储库中的状态。
public static void main(String[] args)throws IOException, InvalidRemoteException, TransportException, GitAPIException {
String remote = "http://192.168.215.29:9090/technology-evaluation/patchgitpluginsample.git";
File localPath = File.createTempFile("TestGitRepository", "");
localPath.delete();
Git git = Git.cloneRepository().setURI(remote)
.setCredentialsProvider(new UsernamePasswordCredentialsProvider("sarathb", "findme"))
.setDirectory(localPath)
.call();
Repository repository = FileRepositoryBuilder.create(new File(localPath.getAbsolutePath(), ".git"));
System.out.println(repository);
List<Ref> branches = git.branchList().call();
for (Ref ref : branches)
{
System.out.println(ref.getName());
}
Iterable<RevCommit> commits = git.log().all().call();
for (RevCommit revCommit : commits) {
System.out.println("");
RevTree tree=revCommit.getTree();
/*System.out.println(revCommit.getName());*/
System.out.println("COMMIT : "+revCommit);
System.out.println("COMMIT MESSAGE : "+revCommit.getFullMessage());
System.out.println("AUTHOR NAME : "+revCommit.getAuthorIdent().getName());
System.out.println("AUTHOR E-MAIL ID : "+revCommit.getAuthorIdent().getEmailAddress());
System.out.println("DATE/TIME : "+revCommit.getAuthorIdent().getWhen());
Status status=git.status().call();
System.out.println("added:"+status.getAdded());
System.out.println("removed:"+status.getRemoved());
TreeWalk treewalk = new TreeWalk(repository);
treewalk.addTree(tree);
treewalk.setRecursive(true);
while (treewalk.next())
{
if(treewalk.getNameString().contains(".java"))
System.out.println("FILE COMMITTED : "+treewalk.getNameString());
}
}}}