git.pull()。call()中受影响文件的列表

时间:2019-05-10 07:24:21

标签: jgit

我是JGit的新手,所以也许我出了点问题,但是我无法从pull命令获得结果。 我的意思是列出受拉影响的文件列表(已修改/添加/删除的文件,...)

我尝试了几件事,但是没有一个给我我需要的信息:

difficulty = int(input("Difficulty: "))

#Check if difficulty is less than 0, or greater than 4
while not 0 < difficulty < 4:
    print("This is not a valid difficulty, please choose 1, 2 or 3")
    difficulty = int(input("Difficulty: "))

print("The playing board was created with difficulty: " + str(difficulty))

这将产生以下输出:

PullResult pull_res = git.pull().setCredentialsProvider(cred).call();
MergeResult merge_res = pull_res.getMergeResult();
FetchResult fetch_res = pull_res.getFetchResult();
java.lang.System.out.println("MergeStat1: "+merge_res.getMergeStatus());
java.lang.System.out.println("####################################");
java.lang.System.out.println("MergeStat2: "+merge_res.getMergedCommits());
java.lang.System.out.println("####################################");
java.lang.System.out.println("FetchRes: "+fetch_res.getMessages());
java.lang.System.out.println("####################################");
java.lang.System.out.println("PullRes1: "+pull_res.getFetchResult());
java.lang.System.out.println("####################################");
java.lang.System.out.println("PullRes2: "+pull_res.getFetchResult().getMessages());
java.lang.System.out.println("####################################");
java.lang.System.out.println("PullRes3: "+pull_res.getFetchResult().toString());
java.lang.System.out.println("####################################");
java.lang.System.out.println("PullRes4: "+pull_res.getFetchResult().getMessages().toString());
java.lang.System.out.println("####################################");
java.lang.System.out.println("PullRes5: "+pull_res.getMergeResult());
java.lang.System.out.println("####################################");
java.lang.System.out.println("PullRes6: "+pull_res.getRebaseResult());
java.lang.System.out.println("####################################");
java.lang.System.out.println("PullRes7: "+pull_res.getFetchedFrom());

我应该怎么做才能从该请求中获取所有受影响文件的列表? (还如何受影响:修改,添加,删除。)

更新

有了Rüdigers的回答,我得出了该问题的以下解决方案:

MergeStat1: Fast-forward
####################################
MergeStat2: [Lorg.eclipse.jgit.lib.ObjectId;@1....
####################################
FetchRes: 
####################################
PullRes1: org.eclipse.jgit.transport.FetchResult@3....
####################################
PullRes2: 
####################################
PullRes3: org.eclipse.jgit.transport.FetchResult@3....
####################################
PullRes4: 
####################################
PullRes5: Merge of revisions a...., 1a.. with base 1a... using strategy recursive resulted in: Fast-forward. 
####################################
PullRes6: null
####################################
PullRes7: origin

1 个答案:

答案 0 :(得分:2)

在调用pull之前,例如使用git.getRepository().resolve("HEAD"),缓冲当前分支的提交ID。

完成提取后,再次读取HEAD提交ID。现在您应该能够在两次提交之间创建差异。

如何显示两次提交之间已更改的文件,已在此处回答:How to show changes between commits with JGit

有关JGit差异API的详细讨论,请参见此处:https://www.codeaffine.com/2016/06/16/jgit-diff/