I have Windows XP. I'd like to upgrade my TortoiseSVN to version 1.7. In order to do that I need to ensure that I can find all SVN working copies on my PC. So they can be updated.
I have found a similar question but it is specific to Powershell. So, I was wondering if there was a more general solution to find all 'SVN working copies' on Win XP.
If I knew the equivalent of 'linux find' on windows I could probably write it myself. But I'm hoping that there may be a bash script out there already (or maybe some solution that's even simpler) that me and others could use.
- scans the computer
- if it finds a directory that contains a directory called ".svn"
- echo that name, and
- breaks from searching that directory any more
I have managed to find all 'SVN working copies' on Win XP.
I did it using the PowerSell script provided by Alexey Shcherbak.
Here is a summary of the process using the PowerShell method.
Test to see if you have PowerShell already installed.
Windows PowerShell is a command-line shell and scripting environment that brings the power of the .NET Framework to command-line users and script writers.
Test to see if it is already installed by attempting to start it.
To start Windows PowerShell from the Run box, click Start, click Run, and type:
If that does not work...
Install it
Once its installed...
Start PowerShell and have a play
Start > All Programs > Windows PowerShell 1.0 > Windows PowerShell
See a brief introduction to PowerShell on YouTube.
Create a PowerShell script
Copy Alexey Shcherbak's PowerSell script (that finds the svn working copies) into a text file and save it as something like
C:\PowerShellScripts\FindSvnWorkingDirectories.ps1
.I modified it slightly to search my C drive and to suppress access denied errors :
To explain what this script does in detail:
$prev = "^$"
initialises$prev
to empty-matching regex;^$
will never match any meaningful value (except startline-endline). This was needed to pass initial check.Gets all objects with name ".svn" (in our case - all files and folders with exact name ".svn"), started from Path, Recursively.
Get-ChildItem
, by default, is an alias of thedir
command.-ErrorAction SilentlyContinue
- Prevents showing errors such as Access to the path 'C:\System Volume Information' is denied as described here.-Recurse
means search recusively.-Force
ensures hidden files are found.-Include ".svn"
identifies the filename that we are searching for.-Path "c:\"
idientifies the path to search.On the next line:
The pipe symbol,
|
, pipes the output ofGet-ChildItem
into the next cmdlets.?{...statements... }
is shorthand for theWhere-Object
cmdlet.$_ is
the way to address "each" entry from pipe. It basically says "If entry is a directory" and "fullname does not start with value from $prev", then "Pass entry to next construct".The entry is then piped to the next statement.
%{}
is shorthand forForeach-Object
. This construct does 2 things:$prev
(without the ".svn" tail).$prev
to the next pipeline sink.Allow PowerShell to run the script
By default, for security, PowerShell's
ExecutionPolicy
does not let you run PowerShell scripts. So, you need to allow it to do so.See Running Windows PowerShell Scripts for more info.
I did the following:
Note: The hash symbol (#) is just shotrthand for the command prompt.
Determine the current
ExecutionPolicy
:If, like mine, its Restricted. Change the policy to allow a script to run:
Run the PowerShell script
Then run the script to find the svn working copies. Note you need to specify the full path to the PowerShell script.
If there are loads of directories on the PC it may take some time. The results should appear.
Copy and Paste the results to somewhere
I did this by selecting the output text with my mouse. Then, to copy it:
Click the PowerShell icon (in the top-left of the Window) > Edit > Copy
Then I pasted it into a text editor.
Revert the PowerShell Excecution Policy to its original state
Since I rarely use PowerShell and I loosened the Excecution Policy only to run this, one-off, script I am going to revert it back to its orignal state for security.
Determine the current
ExecutionPolicy
:Change the policy to revert it to its original state:
So that's how I did it.
As soon as you have powershell, I could provide my full script to upgrade working copies to 1.7
I dont had issues with access rights to "System Volume" dir (that was just accidentially, cause I store all my sources in one folder I have full rights to..). As for your issue with Execution Policy - here nice trick to avoid set it forth and back. You could run powershell with special options to avoid issues with execution policy, user specific profile settings (which could be broken for different reasons) etc:
Also I could clarify what exactly this script do (if you are interested):
Initialize $prev to empty-matching regex - ^$ never match any meaning value (except startline-endline). This was needed to pass initial check
Get all objects with name ".svn" (in our case - all files and folders with exact name ".svn"), started from Path, Recursively. And pipe it to next construct:
?{...statements... } is shortcut to "Where-Object" cmdlet, $_ is the way to address "each" entry from pipe. It could be rewritten similar to
But I wrote it as one-liner for the brevity
%{} is shortcut for Foreach =) And this construct doing 2 things :
And entire result set assigned to $workingCopies as array (any result with more than 1 item will be array)
Foreach element in array - execute command (& sign for "execute as command") "…\svn.exe upgrade "
All the magic here is going to that backtracking $prev element: On first ".svn" entry $prev contains non-matching value so first check in "where" will be reduced to "If entry is directory". Then assigning step will put folder parent dir. Ex. If found dir fullname is c:\projects\project1.root\trunk.svn - $prev will be assigned to "c:\projects\project1.root\trunk\". This trick will help us to filter all lower-level .svn dirs: c:\projects\project1.root\trunk\SubProject1.svn entry - will not pass check "not starts with $prev" And this way we will filter only first level .svn dirs, cause all nested .snv will be filtered by StartsWith($prev) -eq $false
So its pretty simple but appears as some magic =)
BTW Thank you for your own answer here - your efforts greatly inspired me to write this comment and clarify entire script.
Grammar geeks should be summoned to this comment for cleaning and rephrasing my "so-called-English" ;)
For complex and powerful searches on Windows-box I can recommend (I use it in real-life)
You miss the point. SVN-clients 1.7 can (and really must) upgrade existing working copies after installing before usage. Also nore: all dirs inside WC for pre-1.6 versions have .svn dirs, you are interested in only every top-most
And later it may be useful for you
1.6 svn-dir
1.7 svn-dir
To find all .svn files, you can use dir.
dir .svn /s
will do it (though it won't break from scanning subdirectories) or you can use Windows Explorer and ask the little doggy to find all .svn files.or you could download unxutils and use find after all!