Skip to content

Instantly share code, notes, and snippets.

@tjrobinson
Created May 17, 2012 08:02
Show Gist options
  • Save tjrobinson/2717295 to your computer and use it in GitHub Desktop.
Save tjrobinson/2717295 to your computer and use it in GitHub Desktop.
Subversion Tests
# Usage: cd \; . c:\SubversionTests.ps1; BranchingTest1
function Create-LocalRepository
{
param
(
[string]$basePath,
[string]$repositoryName
)
# Create repository
if (!(Test-Path $basePath)) { New-Item $basePath -type directory }
cd $basePath
svnadmin create --fs-type fsfs $basePath\Repository
# Create initial directory structure
New-Item tmp -type directory
New-Item tmp/trunk -type directory
New-Item tmp/tags -type directory
New-Item tmp/branches -type directory
echo $basePath
Set-Location $basePath/tmp
svn import -m 'Initial directory structure' ("file:///" + $basePath.Replace('\','/') + "/Repository")
Set-Location $basePath
Remove-Item tmp -Recurse
}
function BranchingTest1
{
param
(
[string]$testName = "BranchingTest1",
[string]$testDirectory = "C:\SubversionsTests\$testName",
[string]$startingFiles = "C:\Windows\Cursors\*.cur"
)
$svnVersionOutput = svn --version
if (Test-Path $testDirectory) {
Remove-Item $testDirectory -Recurse -Force -ErrorAction Stop
}
$repositoryUrl = 'file:///' + $testDirectory.Replace('\','/') + '/Repository';
# Create local repository
Create-LocalRepository $testDirectory $testName
# Check-out trunk
New-Item $testDirectory\WorkingCopies\trunk -type directory
svn checkout $repositoryUrl/trunk $testDirectory\WorkingCopies\trunk
Set-Location $testDirectory\WorkingCopies\trunk\
# Populate trunk with some sample files
xcopy $startingFiles $testDirectory\WorkingCopies\trunk\
svn status
# Set ignores
svn propset svn:ignore .svn .
svn commit -m "Set svn:ignore property"
# Add and commit to repository
svn add size*.cur
svn commit -m "Added initial set of files"
# Create a branch
Write-Host "*** Create a branch"
svn copy $repositoryUrl/trunk $repositoryUrl/branch1 -m 'Branched from trunk to branch1'
# Check-out branch1
Write-Host "*** Check-out branch1"
New-Item $testDirectory\WorkingCopies\branch1 -type directory
svn checkout $repositoryUrl/branch1 $testDirectory\WorkingCopies\branch1
Set-Location $testDirectory\WorkingCopies\branch1\
touch newFileInBranch1
svn add newFileInBranch1
svn commit -m "Added new file"
ReintegrationMerge $repositoryUrl/branch1 $testDirectory\WorkingCopies\trunk\
$latestRevision = SvnUpdate
# Keep branch alive after reintegration
RecordOnlyMerge $testDirectory\WorkingCopies\branch1\ $testDirectory\WorkingCopies\trunk\
Set-Location $testDirectory\WorkingCopies\branch1\
touch file1.txt
svn add file1.txt
svn commit -m 'Added file1.txt'
Set-Location /
}
function SvnUpdate
{
$out = svn update
$updateRevisionRegex = [regex]'(\d)+'
$latestRevision = $regex.Match($out).Value
return $latestRevision
}
function ReintegrationMerge
{
param
(
[string]$source,
[string]$destination
)
Write-Host "*** Re-integrate $source into $destination"
Set-Location $destination
svn update
svn merge --reintegrate $source
svn commit -m "reintegrate merge from $source to $destination"
}
function RecordOnlyMerge
{
param
(
[string]$source,
[string]$destination
)
# Keep branch alive after reintegration
Set-Location $source
$latestRevision = SvnUpdate
svn merge --record-only -c $latestRevision $destination
svn commit -m "record-only merge from $source to $destination"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment