PoshCode Logo PowerShell Code Repository

init_repoclones.ps1 by Justin Dearing 26 months ago
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/3633"></script>download | new post

A script for creating clones of one or more svn repositories. It can only clone multiple repositories if they only differ by one substring (e.g. they all are svn repos on google code, sourceforge, codeplex, or some other forge.)

  1. <#
  2. .SYNOPSIS
  3. Makes a local copy of one or more remote svn repositories.
  4. .DESCRIPTION
  5. Makes a local copy of one or more remote svn repositories.
  6. .INPUTS
  7. None
  8.     You cannot pipe objects to init-repoclones.ps1
  9. .OUTPUTS
  10. None
  11. .EXAMPLE
  12.  
  13. #>
  14. param (
  15.     [string[]] $Repos = @('protobuf', 'mb-unit', 'opennode2'),
  16.     [string] $RemoteRepoFormat = 'http://{0}.googlecode.com/svn/',
  17.     [string] $LocalRepoBasePath = (Split-Path (Get-Variable MyInvocation).Value.MyCommand.Path),
  18.     [switch] $DeleteExisting
  19. )
  20.  
  21. # check that we have the svn executables we need
  22. @('svnsync.exe', 'svnadmin.exe') | % {
  23.     if (-not (Get-Command $_  -ErrorAction SilentlyContinue)) {
  24.         Write-Host "The executable `"$($_)`" is required by this script and was not found on the path.";
  25.         exit 1;
  26.     }
  27. }
  28.  
  29. $Repos | % {
  30.     $localRepoPath = (Join-Path $($LocalRepoBasePath) $_);
  31.     $localRepoUri = ([uri]($localRepoPath)).AbsoluteUri;
  32.     $remoteRepo = [string]::Format($RemoteRepoFormat, $_);
  33.  
  34.     if (Test-Path $localRepoPath) {
  35.         if ($DeleteExisting) {
  36.             Write-Host "$($localRepoPath) already exists. Deleting . . .";
  37.             rm -r -f $localRepoPath;
  38.         }
  39.         else {
  40.             Write-Host "$($localRepoPath) already exists. Skipping initialization . . .";
  41.         }
  42.     }
  43.     else {
  44.         Write-Host "Cloning $($remoteRepo) into $($localRepoPath)"
  45.         & svnadmin create $localRepoPath;
  46.         [IO.File]::WriteAllText((Join-Path $localRepoPath 'hooks\pre-revprop-change.bat'), 'exit 0');
  47.         & svnsync init $localRepoUri $remoteRepo;
  48.     }
  49.     & svnsync sync $localRepoUri $remoteRepo;
  50.  
  51. }

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me