-
-
Save Gimly/90df046dc38181bb18de to your computer and use it in GitHub Desktop.
| 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) | |
| git checkout -b "tag-$tagName" $remoteBranch | |
| git checkout master | |
| git tag $tagName "tag-$tagName" | |
| git branch -D "tag-$tagName" | |
| } | |
| elseif($remoteBranch -notlike "trunk") | |
| { | |
| git checkout -b $remoteBranch $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 -notcontains "HEAD" -and $remoteBranch -notcontains "master") | |
| { | |
| $branchName = $remoteBranch.Substring(7) | |
| git checkout -b $branchName $remoteBranch | |
| } | |
| } | |
| git checkout master | |
| git remote rm origin | |
| git remote add origin $GitUrl | |
| git push --all |
This is way easier than https://john.albin.net/git/convert-subversion-to-git, which is what I was trying to follow before.
I did have to remove
--stdlayoutfrom line 10 to deal with Subversion repos that weren't setup with the standard trunk/branches/tags structure. I was otherwise getting an error about the Git repository being empty.
Thanks for the tip @JamesSkemp
I'm afraid the condition $remoteBranch -notlike "trunk" in line 28 is always false. Did you mean $remoteBranch -notlike "*trunk"?
The same issue is in line 44. $remoteBranch -notcontains "HEAD" is always false because -contains and -notcontains don't mean "string contains/not contains substring", they mean "if a collection of objects includes ('contains') a particular object". I suppose the condition in line 44 should be $remoteBranch -notlike "*HEAD" -and $remoteBranch -notlike "*master".
This is way easier than https://john.albin.net/git/convert-subversion-to-git, which is what I was trying to follow before.
I did have to remove
--stdlayoutfrom line 10 to deal with Subversion repos that weren't setup with the standard trunk/branches/tags structure. I was otherwise getting an error about the Git repository being empty.