Last active
August 29, 2015 13:57
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Forcing branch selection to be list. If it's just one branch you'd grab the nth character of the branch name instead.