0

There is a need to recursively run svn upgrade in certain directory in filesystem, ignoring non-svn subdirectories:

C:\a>svn upgrade
C:\a\b>svn upgrade
<skip non-svn dir>
C:\a\b\c>svn upgrade
...

This means we need to run svn upgrade command in every folder that has .svn inside it. How this can be done in win32? Found for d in find . -name .svn -type d; do svn upgrade $d/..; done routine for posix OS.

Jaded
  • 1,802
  • 6
  • 25
  • 38

1 Answers1

2

svn upgrade needs to be run at the top level of each working copy - you don't want to recurse into a WC 3 levels deep and then run it there, as you'll hose the WC. Reason: SVN pre-1.7 had a .svn directory in each directory of the working copy, while 1.7+ uses a single .svn in the root of the WC.

So, your recursion has to guarantee that you'll touch the top levels first - then as you go deeper if you find a .svn directory, you know it's a separate WC and not a child of another.

Batch is dead, use PowerShell. Put this in a .ps1 file (or the PowerShell ISE) and run it:

function upgrade-svndirs {
param (
    [string]$PathToUpgrade
    )
    $Dirs = get-childitem $PathToUpgrade|where-object{$_.PSIsContainer};
    foreach ($dir in $dirs) {
        $DirName = $dir.FullName;
        $isWC = Get-ChildItem $DirName -Filter ".svn" -Force;
        if ($isWC) {
            svn upgrade "$DirName";
        }
        upgrade-svndirs -PathToUpgrade $DirName;
    }

}

upgrade-svndirs C:\a;
alroc
  • 27,574
  • 6
  • 51
  • 97
  • That's exactly what I've meant when was asking this question, thanks. Any chance to import this function to PowerShell (at least during some session)? So I could use it few times with different parameters without editing script file itself. Thanks in advance. – Jaded Nov 18 '13 at 14:49
  • You can define it in your `$Profile` or just save it as a `.ps1` file (minus the last line of my code here) and execute it that way as needed (`path_to_ps1file path_to_upgrade`) – alroc Nov 18 '13 at 14:53
  • When I'm executing the whole script (with upgrade-svndirs target_dir; last line) it still tries to execute it in directory where script lies, not target one. When I remove last line and do "upgrade-svndirs.ps1 target-dir" it does nothing at all. Am I missing something? – Jaded Nov 18 '13 at 14:59
  • When I run it eventually, it throws exception at some point: The script failed due to call depth overflow. The call depth reached 1001 and the maximum is 1000. + CategoryInfo : InvalidOperation: (1001:Int32) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : CallDepthOverflow – Jaded Nov 18 '13 at 15:04
  • You didn't specify that your directory tree is so deep. PowerShell v2 has a [recursion depth limit of 1000](http://stackoverflow.com/questions/10755699/how-can-i-configure-call-depth-in-powershell), while v3 is limited by your computer's resources. Can you start deeper in the tree? – alroc Nov 18 '13 at 15:40