使用powershell和svn删除未版本控制的文件

问题描述:

我正尝试使用Powershell编写一个构建脚本来签出代码。我需要能够使用SVN回购中的适当更改来替换对工作副本所做的任何修改。这还包括删除在回购中删除但在工作副本中未删除的任何文件。使用powershell和svn删除未版本控制的文件

不幸的是我不能做一个干净的签出,因为每次构建脚本运行时,检查所有10GB代码的效率会很低。我将如何做到这一点?

我一直在试图沿着这些路线的东西:

&$SVN_EXE revert $workingPath 
&$SVN_EXE update $workingPath 
$x = &$SVN_EXE status $localPath --no-ignore | where {$_ -match "^[\?I]"} | %{$_ -replace "^[\?I]",""} # get the status, get any items with a ? and strip them out 
$x | %{$_ -replace "[`n]",", "} # Replace newlines with commas 
Remove-Item $x # Remove all the unversioned items 

我似乎无法储存的线#3的输出为$ X,我不太清楚,如果它的其余部分是方法来做到这一点。

我不确定这是否是正确的方法,但如果是这样,我似乎无法存储和解析从SVN状态的输出。

有没有人有任何建议?谢谢!

如果你想从你的工作目录中删除未跟踪或忽略的文件,尝试这样的事情:

svn st --no-ignore | %{ if($_ -match '^[?I]\s+(.+)'){ $matches[1]} } | rm -whatif 

取出-whatif一旦您已确认它正在做你想做的事。

我用下面的:

&$SVN_EXE revert $workingPath 
&$SVN_EXE update $workingPath 
&$SVN_EXE status $localPath --no-ignore | 
       Select-String '^[?I]' | 
       ForEach-Object { 
        [Regex]::Match($_.Line, '^[^\s]*\s+(.*)$').Groups[1].Value 
       } | 
       Remove-Item -Recurse -Force -ErrorAction SilentlyContinue