Skip to content

Instantly share code, notes, and snippets.

@togakangaroo
Created November 7, 2013 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save togakangaroo/7357291 to your computer and use it in GitHub Desktop.
Save togakangaroo/7357291 to your computer and use it in GitHub Desktop.
Check out a range of Subversion revisions and recommit them to Mercurial
<#
.SYNOPSIS
Check out a range of Subversion revisions and recommit them to Mercurial
.DESCRIPTION
In the case where you already have an svn and an hg repository and you are transferring commits from one to the other (this is relevant when slowly transitioning svn to hg) you might get in a situation where several commits are made to the svn repository but not to the hg one. In this case you might want to check these out of svn one by one and re-commit to mercurial. This script automates the process.
This script requires an svn and an hg command to exist in your powershell environment. You can do this (assuming Tortoise) by adding 'C:\Program Files\TortoiseSVN\bin' and 'C:\Program Files\TortoiseHg' to your PATH or setting up the appropriate aliases.
.PARAMETER FromRevision
SVN revision to start checking out at.
.PARAMETER FromRevision
SVN revision to stop checking out at.
.PARAMETER NoConfirm
Do not ask for confirmation between each commit
#>
param(
[Parameter(Mandatory=$true)][int]$FromRevision,
[Parameter(Mandatory=$true)][int]$ToRevision,
[switch]$NoConfirm
)
if(-not (Get-Command svn)) { throw "Expected a globally available svn command" }
if(-not (Get-Command hg)) { throw "Expected a globally available hg command" }
if(-not ($FromRevision -le $ToRevision) ) { throw "FromRevision must be less than ToRevision" }
"Removing any mq patches"
hg qpop -a
foreach($revision in $FromRevision..$ToRevision) {
Write-Host "importing $revision"
if( (hg status) ) { throw "There are uncommited mercurial changes" }
svn update --revision $revision
$log = (svn log --revision $revision)
$msg = "Import from svn r$revision - $log".replace('"', "'")
if( -not (hg status) ) { throw "No changes detected" }
Write-Host $msg
if(-not $NoConfirm) {
$continue = Read-Host "Commit into Hg? (Y/N)"
if("Y" -ne $continue) { exit }
}
hg addremove
hg commit -m $msg
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment