Space in branch name causing SVN to GIT migration issues

1.5k Views Asked by At

I'm trying to migrate an old SVN repository over to GIT using svn2git (on my Windows box) using the following command:

svn2git https://my/svn/url --verbose --authors authors.txt

and things were running okay until I hit the following error:

fatal: Not a valid object name refs/remotes/svn/VS2010 Port
cat-file commit refs/remotes/svn/VS2010 Port: command returned error: 128

It seems that someone (ages back) created a branch with a space in the name and this is causing havoc on the process. Running git branch -a shows the branch in question:

remotes/svn/VS2010%20Port

I did some searching around Google and StackOverflow and came across a few posts including this one (although it is referring to tags).

First I attempted the suggestion of removing the branch with git branch -r -d svn/VS2010%20Port (retaining this branch is not important) and then I reran my svn2git command. It begins running and eventually fails with the same error. I also tried removing the branch and adding the flag --exclude '.*VS2010.*' to my svn2git command but this didn't help:

svn2git https://my/svn/url --verbose --authors authors.txt --exclude '.*VS2010.*'

Next, I tried the other suggestion of running the mv command to move the file/directory with the %20 in the name to one with an actual space:

mv VS2010%20Port VS2010\ Port

Since my issue isn't with tags I wasn't 100% where to run this but I tried in the following locations:

  • .git\svn\refs\remotes\svn
  • .git\refs\remotes\svn
  • .git\logs\refs\remotes\svn

When I ran the svn2git command afterwards I eventually got the same issue.

Finally I found this post which is specifically about branches but the solution was to edit the packed-refs file and replace %20 with spaces. Although I didn't see the VS2010%20Port branch listed here so I could not go through with this solution.

Does anyone have any suggestions on something I could try or something I may have missed?

Update: I was able to get some progress happen by adding the --ignore-refs flag with a regex that would match the VS2010 Port string. Its a large repository so it took a very long time but eventually it seemed to finish. Unfortunately, I saw no files in the directory (just the .git directory) so I'm assuming something went wrong. I decided to take a step back and try again fresh with the git svn clone command and this time I provided the --ignore-refs and --ignore-paths flags from the start. Hopefully I'll get better results this time.

3

There are 3 best solutions below

1
On BEST ANSWER

Just to put an end to this question, I was able to get this process working thanks to the various comments and suggestions. In the end I moved away from svn2git and I was able to get my repository migrated (to a point that I'm satisfied with) using git svn clone along with the --ignore-refs option. I'm not exactly clear why svn2git or git svn init followed by git svn fetch did not work but in the end I got.

2
On

It looks like this svn2git script supports "--branches" option where you can pass the names (relative paths) of the SVN branches you want to import. Something like --branches X --branches Y --branches Z should import 3 branches: X, Y and Z.

Also try --nobranches --trunk trunk option which doesn't import any branches, just the trunk.

--exclude probably didn't work, because it seems to filter paths to directories inside the repo, not the branch names.

In any case the svn2git script is not a black box, it is quite short and well-written: https://github.com/nirvdrum/svn2git/blob/master/lib/svn2git/migration.rb

Feel free to read through, debug it with print/puts statements, and modify to your use case.

The script is based on git svn commands.

0
On

At one point I gave decided to rename our tags containing blanks to underscores using this batch file:

setlocal ENABLEDELAYEDEXPANSION
echo off
set url=https://subversion.server/path_to_repo/tags/
FOR /F "delims=#" %%f IN ('svn list %url%') DO ( echo %%f
set file_name_with_blank="%%f"
set file_name_underscore=!file_name_with_blank: =_!
set file_name_without_quote=!file_name_underscore:"=!
echo !file_name_without_quote!
svn mv "%url%%%f" %url%!file_name_without_quote! -m "replace blank by underscore"

)

pause