Skip to content

Instantly share code, notes, and snippets.

@davidroberts63
Last active August 29, 2015 13:57
Show Gist options
  • Save davidroberts63/9651449 to your computer and use it in GitHub Desktop.
Save davidroberts63/9651449 to your computer and use it in GitHub Desktop.
Powershell script for SVN merging branch to trunk. Reverts, Updates and merges. Offers names of available branches if none is specified.
param(
[string] $branchName = ''
)
Write-Host "Reverting..."
svn revert -R .\
Write-Host "Cleaning up..."
$toRemove = svn status --no-ignore | Where-Object { $_.StartsWith("?") -or $_.StartsWith("I") } | % { $_.SubString(8) }
if ($toRemove)
{
$toRemove | Remove-item -Force -Recurse
}
svn update
# Merging
$trunk = (svn info | Where-Object { $_.StartsWith("URL") }).SubString(4).Trim()
if (!$branchName)
{
Write-Host "Getting list of branches available for merging..."
$branches = (svn list $trunk.Replace("trunk","branches"))
$branches | %{$index=0} { Write-Host "[$index] $_" -foregroundcolor green; $index++ }
Write-Host "Enter number for branch to merge: " -foregroundcolor yellow -NoNewline
$branchIndex = Read-Host
if ($branchIndex -ge $branches.Count)
{
Write-Host "Branch number does not exist. Quitting."
return;
}
$branchName = @($branches)[$branchIndex]
}
if ($branchname -ne '')
{
Write-Host "Merging..."
$branch = $trunk.Replace("/trunk", "/branches/$branchName");
Write-Host " from branch: $branch"
Write-Host " to trunk: $trunk"
svn merge $branch
}
@davidroberts63
Copy link
Author

Forcing branch selection to be list. If it's just one branch you'd grab the nth character of the branch name instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment