具体来说,我想知道如何执行命令中的“删除未版本控制/忽略文件”部分。我想这样做,所以我可以自己模拟一个干净的结账,我们的存储库很大,一个完整的结账需要一段时间。
答案 0 :(得分: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 $_"
}
答案 1 :(得分: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更新撤回。