You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用SVN Kit执行doUpdate报E155007错误,如何解决?

解决SVNKit更新时的E155007: None of the targets are working copies异常

这个异常的核心原因是你调用doUpdate的目标文件还不是SVN工作副本——你先执行更新操作,再通过doAdd将文件纳入版本控制,此时更新操作必然失败,因为未被add的文件不属于SVN工作副本范畴。

修复方案

调整代码逻辑,区分已在版本控制中的文件(工作副本)和新创建的未版本化文件:

  1. 先判断目标文件是否属于SVN工作副本
  2. 仅对工作副本文件执行update操作
  3. 对未版本化文件直接执行add操作,最后统一提交

修正后的代码示例

SVNClientManager clientManager = ...; // 你的clientManager初始化逻辑
String commitMessage = ...;
File[] files = ...;

// 1. 分离工作副本文件和未版本化文件
List<File> workingCopyFiles = new ArrayList<>();
List<File> newFiles = new ArrayList<>();

SVNStatusClient statusClient = clientManager.getStatusClient();
for (File file : files) {
    try {
        SVNStatus status = statusClient.doStatus(file, false);
        if (status != null && status.isVersioned()) {
            // 已在版本控制中,属于工作副本
            workingCopyFiles.add(file);
        } else {
            // 未版本化文件
            newFiles.add(file);
        }
    } catch (SVNException e) {
        // 处理文件不存在等异常情况
        e.printStackTrace();
    }
}

// 2. 仅更新工作副本文件
if (!workingCopyFiles.isEmpty()) {
    SVNUpdateClient svnUpdateClient = clientManager.getUpdateClient();
    svnUpdateClient.doUpdate(workingCopyFiles.toArray(new File[0]), SVNRevision.HEAD, SVNDepth.INFINITY, false, false);
}

// 3. 添加未版本化文件
if (!newFiles.isEmpty()) {
    SVNWCClient wcClient = clientManager.getWCClient();
    for (File file : newFiles) {
        wcClient.doAdd(file, false, false, false, SVNDepth.INFINITY, false, false);
    }
}

// 4. 统一提交所有文件
if (!workingCopyFiles.isEmpty() || !newFiles.isEmpty()) {
    SVNCommitClient commitClient = clientManager.getCommitClient();
    commitClient.doCommit(files, false, commitMessage, null, null, false, false, SVNDepth.INFINITY);
}

关键说明

  • 使用SVNStatusClient.doStatus()判断文件是否已被版本化,这是SVNKit中检查工作副本状态的标准方式
  • 必须确保update操作仅针对已纳入版本控制的文件,未add的文件不能执行update
  • 保持add和commit的逻辑,最后统一提交所有变更(包括更新后的修改和新增文件)

内容的提问来源于stack exchange,提问作者Gukkey

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 04:35:09