2012-01-31 93 views
2

我正嘗試使用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狀態的輸出。

有沒有人有任何建議?謝謝!

回答

4

如果你想從你的工作目錄中刪除未跟蹤或忽略的文件,嘗試這樣的事情:

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

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

0

我用下面的:

&$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 
相關問題