0

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.

Fizz
  • 3,427
  • 4
  • 27
  • 43
  • Has your problem been solved yet? – Marina Liu May 22 '18 at 05:57
  • I'll update the question. – Fizz May 22 '18 at 20:30
  • What if you use `git svn clone` command directly? – Marina Liu May 23 '18 at 09:48
  • That what I'm testing now :D – Fizz May 23 '18 at 13:00
  • Use the command `git svn clone https://my/svn/url --trunk='trunk' --branches='branches' --tags='tags'` can migrate all the branches into git repo (including `VS2010 Port`). And if you want to switch to the branch `VS2010 Port`, you can use the command `git checkout -b branchname remotes/origin/VS2010%20Port`. If there has any problems during migration, free feel let me know :) – Marina Liu May 24 '18 at 08:50
  • It looks like `git svn clone` did the trick using the `--ignore-refs` flag. Now I'm not sure how to close this question... – Fizz May 24 '18 at 12:36
  • The only downside is that it seems like no branches were pulled in just the trunk... although the history is intact. – Fizz May 24 '18 at 14:45
  • Sorry for the delay. `git svn clone` command can migrate the histories for all branches (even if there has blank space in branch name like `VS Port`). And if you add the options like `--branches='branches' ` in `git svn clone` command, it should clone all the branches into git repo (you can double check by `git branch -a`). – Marina Liu May 31 '18 at 06:03
  • old question but making this comment just in case someone else is wondering. git svn clone wont pull in the branches or tags, it just adds them as remotes. makes sense because in a standard SVN layout everything should be in trunk anyhow. – jkratz Jul 25 '19 at 14:11

3 Answers3

0

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.

battlmonstr
  • 5,841
  • 1
  • 23
  • 33
  • Yeah I've already had to modify the `migration.rb` file of `svn2git` for other issues I hit. I believe I did try the `--nobranches` option (with no luck) but I did not use the `--trunk` option with it. One thing I'm messing with at the moment is calling `git svn fetch` myself and using the `--ignore-refs` flag (since svn2git doesn't use that flag) to ignore `.*VS2010.*`. So far it has run without issue, so I have my fingers crossed. – Fizz May 17 '18 at 19:52
  • So far I've made the most progress with the `--ignore-refs` option. – Fizz May 21 '18 at 12:57
0

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.

Fizz
  • 3,427
  • 4
  • 27
  • 43
  • because git clone does more work than an init followed by fetch ;) In general clone does an init, adds a remote, does a fetch, then a checkout for the main branch of the repo you're cloning. git svn adds some perl into the mix but the behavior really isn't any different. you didn't see any files before because the checkout part probably never happened. – jkratz Jul 25 '19 at 14:25
0

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
Florian Straub
  • 826
  • 9
  • 18