2012-08-07 78 views
4

我写一段代码,一旦一个SVN工作副本内的任何地方执行,定位根:如何使用svnkit列出本地修改/未版本化的文件?

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

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

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

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

回答

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只是一个本地值对象,其中包含有关存储库本身的各种详细信息。

+0

这个伎俩。非常感谢你 – radai 2012-08-08 06:55:29

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

为了包含未版本控制的文件,我发现我必须从'if'语句中删除'statusType!= SVNStatusType.STATUS_NONE' – conorgriffin 2015-08-04 11:59:05

相关问题