2011-06-08 47 views

回答

2

不知道Jenkins如何做到这一点,但我认为它使用svn status来查找未受版本控制/忽略的文件。

这里的2个PowerShell脚本我用它来做到这一点:

#remove_ignored.ps1 (only removes ignored files, leaves unversioned) 

param([switch] $WhatIf) 

# Find all items with the status of I in svn 
# Strip the leading status code and whitespace 
# Grab the item for said path (either FileInfo or DirectoryInfo) 
$paths = (svn status --no-ignore | Where-Object {$_.StartsWith('I')} | ForEach-Object {$_.SubString(8)} | ForEach-Object {Get-Item -Force $_}) 

$paths | ForEach-Object { 
    if (-not $WhatIf) { 
     # Check if the path still exists, in case it was a nested directory or something strange like that 
     if ($_.Exists) { 
      # If its a directory info, tell it to perform a recursive delete 
      if ($_ -is [System.IO.DirectoryInfo]) { $_.Delete($true) } 
      else { $_.Delete() } 
     } 
    } 

    Write-Host "Deleted $_" 
} 

#remove_unversioned.ps1 (removes both ignored and unversioned files) 
param([switch] $WhatIf) 

# Find all items with the status of I or ? in svn 
# Strip the leading status code and whitespace 
# Grab the item for said path (either FileInfo or DirectoryInfo) 
$paths = (svn status --no-ignore | Where-Object {$_.StartsWith('I') -or $_.StartsWith('?')} | ForEach-Object {$_.SubString(8)} | ForEach-Object {Get-Item -Force $_}) 

$paths | ForEach-Object { 
    if (-not $WhatIf) { 
     # Check if the path still exists, in case it was a nested directory or something strange like that 
     if ($_.Exists) { 
      # If its a directory info, tell it to perform a recursive delete 
      if ($_ -is [System.IO.DirectoryInfo]) { $_.Delete($true) } 
      else { $_.Delete() } 
     } 
    } 

    Write-Host "Deleted $_" 
} 
+0

完美,谢谢:) – 2011-06-08 13:44:49

2

这个选项在UpdateWithCleanUpdater实现。从source

@Override 
protected void preUpdate(ModuleLocation module, File local) throws SVNException, IOException { 
    listener.getLogger().println("Cleaning up " + local); 

    clientManager.getStatusClient().doStatus(local, null, SVNDepth.INFINITY, false, false, true, false, new ISVNStatusHandler() { 
     public void handleStatus(SVNStatus status) throws SVNException { 
      SVNStatusType s = status.getCombinedNodeAndContentsStatus(); 
      if (s == SVNStatusType.STATUS_UNVERSIONED || s == SVNStatusType.STATUS_IGNORED || s == SVNStatusType.STATUS_MODIFIED) { 
       listener.getLogger().println("Deleting "+status.getFile()); 
       try { 
        File f = status.getFile(); 
        if (f.isDirectory()) 
         hudson.Util.deleteRecursive(f); 
        else 
         f.delete(); 
       } catch (IOException e) { 
        throw new SVNException(SVNErrorMessage.create(SVNErrorCode.UNKNOWN, e)); 
       } 
      } 
     } 
    }, null); 
} 

貌似代码使用SVNKit获取SVN状态,然后删除所有未版本控制,忽略,和修改文件和目录。

令我感到惊讶的是,修改后的文件被删除而不是被还原,但它们会通过SVN更新被拉回来。