Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Importing SVN repository into GitLab

Procedure detailed here and corresponding used scripts are based on svn-to-git Gist from Nathan Sweet

  1. Prepare

  • Make sure svn, git svn and a version of read supporting -d option (such as Bash's) are installed.

  • It is advised to make SVN tools aware of your credentials if any (username and password) to avoid continuous password prompt during bulk processing (once per svn invocation). See credentials caching paragraph in Version Control with Subversion book)

  • Configure git:

      git config --global user.name "git-maintenance"
      git config --global user.email "gitlab@example.com"
  1. Repository list

Create a svnlist.txt file and fill it with SVN repository's URL and desired Git-name (if empty, basename's URL will be used) separated by a space (" ").


http://svn.example.com/foobar_v3 foobar
http://reflectasm.googlecode.com/svn reflect-asm

Execute list clean/read script:

sh read-svnlist.sh

It will compute omitted names and create run-convert.sh (cf. step 3). If any correction were to be made on file svnlist.txt, just re-execute read-svnlist.sh to take them into account.

  1. Authors file

Goal here is to have a SVN-Git mapping file (here named authors.txt) to supply to --authors-file option of git svn clone.

Content example:

loginname = Joe User <user@example.com>
john-doe = John Doe <jdoe@example.com>
foo-bar = Foo Bar <fbar@example.com>

Method 1: SVN log

This method uses authors.sh script to fetch and parse SVN repositories' log to find authors.

Create a script run-authors.sh to execute authors.sh on every repository:

echo "rm authors.txt" > run-authors.sh
awk '{ print "sh authors.sh " $1 }' svnlist.txt >> run-authors.sh

Executer obtained script:

sh run-authors.sh

Open and adapt authors.txt file to put names and e-mail addresses that GitLab will recognize.

Method 2: Existing list

This methode uses a CSV file (separator is ";") containing, in this order, SVN usernames, name and e-mail address. It's faster than first method when such information are in a directory or a database because there is no need to parse entire log of every repository.

Create authors.txt file with entries of SVN users that are not present in CSV file (special maintenance/deployment users):

cat > authors.txt <<'EOT'

svn-maintenance = git-maintenance gitlab@example.com USVN = git-maintenance gitlab@example.com EOT

Import the CSV file (here named uid-to-name+mail.csv):

sh authors-from-csv.sh uid-to-name+mail.csv

To re-sort the file (after any manual change):

cat authors.txt | sort -u > authors.tmp
mv authors.tmp authors.txt
  1. Conversion

Execute run-convert.sh script (created by read-svnlist.sh during step 1.):

  1. Import into GitLab

to-gitlab.sh script moves every *.git folders from svnlist.txt into designated GitLab's namespace and asks GitLab to take them into account.

If previous steps were not executed on the computer hosting GitLab, firstly copy every *.git folders and the two following files on the GitLab server before running the command below (on GitLab server):

  • svnlist.txt
  • to-gitlab.sh

Executer the bare git repositories GitLab import:

./to-gitlab.sh git git /home/git/repositories/foobar_namespace/

Here arguments are respectively:

  1. GitLab's user

  2. GitLab's group

  3. Path to the namespace where repositories are to be imported (can be moved afterwards directly via GitLab UI)

  4. Appendix: Working files list

  1. svnlist.txt: Contains the list of SVN repositories to process.
  2. authors.txt: Contains the list of SVN users having worked on theses repositories.
  3. run-convert.sh: Executes SVN to GIT conversion of every repository (created by read-svnlist.sh)
  4. run-authors.sh: Executes author lookup (authors.sh) on every repository (created manually)