如何使用svnkit列出本地修改/未版本控制的文件?

时间:2012-08-07 18:05:11

标签: java svn svnkit

我正在编写一段代码,一旦在SVN工作副本中执行,就会找到根目录:

File workingDirectory = new File(".").getCanonicalFile();
File wcRoot = SVNWCUtil.getWorkingCopyRoot(workingDirectory, true);

获取给定此根的存储库URL,在给定此信息的情况下构建SVNClientManager,现在我停留在如何获取工作副本中不在存储库中的任何内容的列表 - 这包括本地 - 修改过的文件,未解决的合并,无版本的文件,我很乐意听到任何我可能错过的内容。

我该怎么做? 这个片段似乎需要访问存储库本身,而不是WC:

clientManager.getLookClient().doGetChanged(...)

2 个答案:

答案 0 :(得分:9)

public static List<File> listModifiedFiles(File path, SVNRevision revision) throws SVNException {
    SVNClientManager svnClientManager = SVNClientManager.newInstance();
    final List<File> fileList = new ArrayList<File>();
    svnClientManager.getStatusClient().doStatus(path, revision, SVNDepth.INFINITY, false, false, false, false, new ISVNStatusHandler() {
        @Override
        public void handleStatus(SVNStatus status) throws SVNException {
            SVNStatusType statusType = status.getContentsStatus();
            if (statusType != SVNStatusType.STATUS_NONE && statusType != SVNStatusType.STATUS_NORMAL
                    && statusType != SVNStatusType.STATUS_IGNORED) {
                fileList.add(status.getFile());
            }
        }
    }, null);
    return fileList;
}

答案 1 :(得分:4)

这为您提供了本地修改,即它不会查看存储库中未在您的工作副本中更改的内容

static def isModded(SvnConfig svn, File path, SVNRevision rev) {
    SVNClientManager mgr = newInstance(null, svn.username, svn.password)
    logger.debug("Searching for modifications beneath $path.path @ $rev")
    mgr.statusClient.doStatus(path, rev, INFINITY, false, false, false, false, { SVNStatus status ->
        SVNStatusType statusType = status.contentsStatus
        if (statusType != STATUS_NONE && statusType != STATUS_NORMAL && statusType != STATUS_IGNORED) {
            lmodded = true
            logger.debug("$status.file.path --> lmodded: $statusType")
        }
    } as ISVNStatusHandler, null)
    lmodded
}

我对此的代码是groovy,但希望使用svnkit api足够明显。 SvnConfig只是一个本地值对象,包含有关存储库本身的各种详细信息。