Using powershell and svn to delete unversioned files

杀马特。学长 韩版系。学妹 提交于 2019-12-10 18:57:15

问题


I'm trying to write a build script to checkout code using Powershell. I need to be able to replace any modifications which were made to the working copy with the appropriate changes from the SVN repo. That also includes deleting any files which were deleted in the repo but not deleted in the working copy.

Unfortunately I cannot do a clean checkout, since it would be to inefficient to check out all 10GB of code every time the build script is run. How would I do this?

I've been trying something along these lines:

&$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

I cannot seem to store the output of line #3 into $x, and I'm not quite sure if the rest of it is the way to do it.

I'm not sure if this is the proper way to go, but if it is, I cannot seem to store and parse the output from SVN status.

Does anyone have any suggestions? Thanks!


回答1:


If you want to remove untracked and ignored files from your working directory, try something like this:

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

Remove the -whatif once you have confirmed that it is doing what you want it to do.




回答2:


I used the following:

&$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



回答3:


cd $PATH

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

Please refer Source



来源:https://stackoverflow.com/questions/9082706/using-powershell-and-svn-to-delete-unversioned-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!