0

I have installed scm-manager 1.45 as a service on my windows server 2012 r2.

I have a subversion repository dump file. I managed to import that to a subversion repo in scm-manager. But I would really want to migrate that to a git repository instead, but I can't seem to figure out how. I want all the commit history to follow.

madbys
  • 31
  • 10
  • I'm not familiar with that app but they [don't mention anything](https://www.scm-manager.org/) about having a migration feature. Perhap's that's why you can't figure out how to use it :-? – Álvaro González Apr 23 '15 at 14:30
  • Exactly. I have written in their issue report about it and waiting for an answer. But that can take forever. So I need to figure out another way. This is not important, it is just a "nice to have". :-) – madbys Apr 24 '15 at 08:59

2 Answers2

1

Outside of the tool you're using to keep your shared repository, svn-git and a little of command line magic shall solve your problem

I'm supposing that the migration is done from an Unix-Like system, e.g. Linux, mac or even cygwin running in a windows machine; You may try use the 'Git Bash' installed with msysgit in windows platforms if you don't have a proper cygwin installation available


1# Obtain the list of contributors to the SVN repository

extract the list of committers to the SVN repository, for that, run (from the root of your SVN repository):

svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors-transform.txt

It shall create a file with an authors list like:

jsmith = jsmith <jsmith>

which you'll need to modify into something like:

jsmith = John Smith <john.smith@evil_corporation.com>

This step is importat, since it is which git will use in the next step to translate the SVN committer IDs into git committer IDs (note that you may create this file manually if you prefer so)


2# Clone the SVN repository as a Git repository

For this, execute:

git svn clone <SVN_repo_URL> -A authors-transform.txt --stdlayout ~/svn-git-migration

Where:

  • <SVN_repo_URL> is your SVN repository and authors-transform.txt is the file you just created.

Note that it will work fine if you've used the "standard" SVN branch nomenclature for your SVN repository layout, if it is not the case, you'll need to indicate to git-svn the name of the "folders" where your branches have been created by replacing the --stdlayout argument by:

  • -T (for trunk path)

  • -b (for branches path)

  • -t (for tags path) parameters

(you may find a detailed explanation about the git-svn clone command here)

This step may take a while (it elaborates the git history from the SVN deltas one by one), but when it is completed, a git version of your SVN repo will be in your home directory, within the svn-git-migration folder (specify any other path in the command if you wish)


3# Convert the repository (tags and main branch) structure to git

Note: these commands need to be executed from within your new git repository, so you'll need to move into the folder where you've cloned the repo in the prev step

Subversion does not handle the tags in the same way git does; Git tahs are retaled to a single commit (a git tag simply contains a commit ID), but SVN tags are an special king of branches, so here, we need to locate the repository tag branches (looking into refs/heads/tags) and apply a tag on the tip of all of them:

git for-each-ref --format='%(refname)' refs/heads/tags |
cut -d / -f 4 |
while read ref
do
  git tag "$ref" "refs/heads/tags/$ref";
  git branch -D "tags/$ref";
done

Additionally, We will need to rename the main branch (trunk in SVN into the git main branch 'master'

git branch -m trunk master

Now just push to your new/migrated git repository to your git server (scmmanager?) and you're done :-). remember that you'll need to add your git server repository as a remote, here you may find some help to do so.

Álvaro P.
  • 1,031
  • 9
  • 9
  • When I do the first step, trying to list all authors, I get: ''' is not recognized as an internal or external command, operable program or batch file. What does it mean? What is " ''' "? I copy-pasted the line. – madbys Apr 24 '15 at 08:52
  • Do you have svn installed in the machine? try `svn --version` to check that the command is recognised. – Álvaro P. Apr 24 '15 at 12:25
  • Try to call the different piped functions independently " ''' " is a really weird "command"; are you sure you fully copy-pasted the command? (It is quite long and you may have not selected the entire line :-S) – Álvaro P. Apr 24 '15 at 12:31
  • I skipped the first part and did it manually instead. Now I have another problem, in my command window it says: **mkdir.: No such file of directory at C:\Program Files (x86)\Git/libexec/git-core\git-svn line 493**. In that file at that line it says: **mkpath([$repo_path]) unless -d $repo_path;** – madbys Apr 24 '15 at 13:06
  • All function is: sub init_subdir { my $repo_path = shift or return; mkpath([$repo_path]) unless -d $repo_path; chdir $repo_path or die "Couldn't chdir to $repo_path: $!\n"; $ENV{GIT_DIR} = '.git'; $_repository = Git->repository(Repository => $ENV{GIT_DIR}); } – madbys Apr 24 '15 at 13:06
  • **svn --version** gives me **svn version 1.8.13 (r1667537)** - yes, svn is installed. – madbys Apr 24 '15 at 13:09
  • ...Please, since the `git svn clone ` downloads the repository to your disk, make sure you have write permissions whenever you're trying to clone the repository. – Álvaro P. Apr 25 '15 at 09:02
  • Try to check if it it works with a random SVN repository e.g. `git svn clone https://github.com/jeffmincey/IntelHEX` (so we may discard if it is an issue with your machine or not) – Álvaro P. Apr 25 '15 at 09:06
  • I tried with with another svn repo, and I got this little msg: **Couldn't open a repository: Unable to open an ra_local session to URL: Unable to open repository 'file:///mysvnrepo...: Expected FS format '2'; found format '6' at /usr/lib/per15/site_perl/Git/SVN.pm line 148** – madbys Apr 27 '15 at 07:24
  • I believe that your answer to my problem is correct. I have found the same answer on another website as well. It is just all my settings, permissions etc that is the problem. Should I perhaps mark this as solved/best answer? – madbys Apr 27 '15 at 09:26
  • Finally! I managed to fix it. It was so much simplier than I thought. When I **edit some read/write permission** /thanks for the tip) where my scm-manager repositories are located I could just do: Step1: Create a new directory mkdir MyProject; Step 2: step into my new directory; Step 3: **git svn clone URLfromSCMmanagerSvnRepo**; Step 4: Add the new repository via SCM-manager "Import repositories". Solved! Sometimes is the simpliest solution the best. – madbys Apr 27 '15 at 12:20
  • Great!! :-D (PS: remember to convert your SVN tags into git tags or they'll appear as branches instead of tags in your git repository [I don't know if scm-manager does it automatically or not]) – Álvaro P. Apr 27 '15 at 16:28
1

See that you have read/write permissions where the SCM-manager repositories are located.

  1. Create new directory MyProject where the SCM-manager repositories are located;
  2. Step into MyProject;
  3. Do the command git svn clone theURLfromSCMmanagerSvnRepo;
  4. Add the new repository via SCM-manager "Import repositories" -->Choose Git in the Repository Import Wizard -->Import from directory.
  5. It should now detect your new repository.
madbys
  • 31
  • 10