JGIT库可以通过git.status().call()来获取当前working copy的文件变动情况,功能类似与命令行的git status,以下从源码角度简析git status的实现原理:
public Status call() throws GitAPIException, NoWorkTreeException {
if (workingTreeIt == null)
workingTreeIt = new FileTreeIterator(repo);
try {
IndexDiff diff = new IndexDiff(repo, Constants.HEAD, workingTreeIt);
if (ignoreSubmoduleMode != null)
diff.setIgnoreSubmoduleMode(ignoreSubmoduleMode);
if (paths != null)
diff.setFilter(PathFilterGroup.createFromStrings(paths));
if (progressMonitor == null)
diff.diff();
else
diff.diff(progressMonitor, ProgressMonitor.UNKNOWN,
ProgressMonitor.UNKNOWN, ""); //$NON-NLS-1$
return new Status(diff);
} catch (IOException e) {
throw new JGitInternalException(e.getMessage(), e);
}
}</