How to list locally-modified/unversioned files using svnkit?

﹥>﹥吖頭↗ 提交于 2019-12-22 08:14:38

问题


I'm writing a piece of code that, once executed anywhere inside an SVN working copy, locates the root:

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

gets the repository url given this root, builds an SVNClientManager given this info and now I'm stuck at how to get a list of anything in the working copy that is not in the repository - this includes locally-modified files, unresolved merges, unversioned files and I'll be happy to hear any anything else I might have missed.

How do I do that ? This snippet seems to require access to the repository itself, not the WC:

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

回答1:


This gives you local modifications, i.e. it doesn't look at things that have changed in the repository that are not in your working copy

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
}

The code I have for this is in groovy but hopefully the use of the svnkit api is obvious enough to work with. SvnConfig is just a local value object containing various details about the repository itself.




回答2:


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;
}


来源:https://stackoverflow.com/questions/11851584/how-to-list-locally-modified-unversioned-files-using-svnkit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!