-
-
Save kcd83/5dcc6a186f8e8290fc4cf5e6a1f234c6 to your computer and use it in GitHub Desktop.
Import a SVN repository into a Git repository, complete with branches and tags. Script inspired by the method described by StackOverflow answer http://stackoverflow.com/a/3972103/123597
This file contains 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( | |
[Parameter(Mandatory=$true, Position=1)] | |
[string]$SvnFolderPath, | |
[Parameter(Mandatory=$true, Position=2)] | |
[string]$TargetFolder, | |
[Parameter(Mandatory=$true, Position=3)] | |
[string]$GitUrl | |
) | |
git svn clone --stdlayout --no-metadata -A users.txt $SvnFolderPath "$TargetFolder-tmp" | |
cd "$TargetFolder-tmp" | |
$remoteBranches = git branch -r | |
foreach($remoteBranch in $remoteBranches) | |
{ | |
$remoteBranch = $remoteBranch.Trim() | |
if($remoteBranch.StartsWith("tags/")) | |
{ | |
$tagName = $remoteBranch.Substring(5) | |
Write-Host -ForegroundColor Green "Setting tag [${tagName}] from SVN [${remoteBranch}]" | |
git checkout -b "tag-$tagName" $remoteBranch | |
git checkout master | |
git tag $tagName "tag-$tagName" | |
git branch -D "tag-$tagName" | |
} | |
elseif($remoteBranch -notlike "*/trunk") | |
{ | |
Write-Host -ForegroundColor Green "Checkout local branch for SVN [${remoteBranch}]" | |
git checkout -b $remoteBranch $remoteBranch | |
} | |
else | |
{ | |
Write-Host -ForegroundColor Green "Skip trunk SVN [${remoteBranch}]" | |
} | |
} | |
cd .. | |
git clone "$TargetFolder-tmp" $TargetFolder | |
rm -Recurse -Force "$TargetFolder-tmp" | |
cd $TargetFolder | |
$remoteBranches = git branch -r | |
foreach($remoteBranch in $remoteBranches) | |
{ | |
$remoteBranch = $remoteBranch.Trim() | |
if($remoteBranch -notlike "*/HEAD" -and $remoteBranch -notlike "*/master") | |
{ | |
Write-Host -ForegroundColor Green "Checkout GIT TMP [${remoteBranch}]" | |
$branchName = $remoteBranch.Substring(7) | |
git checkout -b $branchName $remoteBranch | |
} | |
else | |
{ | |
Write-Host -ForegroundColor Green "Skip GIT TMP [${remoteBranch}]" | |
} | |
} | |
git checkout master | |
git remote rm origin | |
git remote add origin $GitUrl | |
git push --all |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Applied these suggestions https://gist.github.com/Gimly/90df046dc38181bb18de#gistcomment-3090187