SVN to GitLab How-To

1. Import Subversion repository

In this chapter the one-time import process is described. As result of the import a Git repository will be created from an SVN repository specified but it won’t be kept in sync the SVN repository.

1.1 Download SubGit

As the first step one should get the latest version of SubGit from download page and unpack it. For more details and platform-specific installation information refer to SubGit book.

up

1.2 Create Git repository

To import an SVN repository to a Git repository served by GitLab you need to create new Git repository (new project in GitLab therminology) first. Click New project button displayed as ‘+’.

Create new project from GitLab

Give a name to your project and click Create project button. Create new project from GitLab

up

1.3 Start importing

Find a directory on the server with GitLab where Git repositories are stored. Usually this directory is

/var/opt/gitlab/git-data/repositories/username

where username is name of the user in GitLab.

Usually this directory has git:git permissions. So it’s better to change current user to git:

$ sudo su git
$ id
uid=999(git) gid=999(git) groups=999(git)

Enter that directory (in this example we assume the current user is root):

$ cd /var/opt/gitlab/git-data/repositories/root
$ pwd
/var/opt/gitlab/git-data/repositories/root
$ ls
kafka.git  kafka.wiki.git

Start importing

$ subgit import https://svn.apache.org/repos/asf/kafka 
...
                                                                                                                                                                                                                                  
IMPORT SUCCESSFUL

up

2. Mirror Subversion repository

In this chapter the SVN repository mirroring feature is described. Any change performed to the Git repository will be automatically translated to the SVN repository and vice versa.

2.1 Download SubGit

As the first step one should get the latest version of SubGit from download page and unpack it. For more details and platform-specific installation information refer to SubGit book.

up

2.2 Create Git repository

To mirror an SVN repository to a Git repository served by GitLab you need to create new Git repository (new project in GitLab therminology) first. Click New project button displayed as ‘+’.

Create new project from GitLab

Give a name to your project and click Create project button. Create new project from GitLab

up

2.3 Configure Git repository

Find a directory on the server with GitLab where Git repositories are stored. Usually this directory is

/var/opt/gitlab/git-data/repositories/username

where username is name of the user in GitLab.

Usually this directory has git:git permissions. So it’s better to change current user to git:

$ sudo su git
$ id
uid=999(git) gid=999(git) groups=999(git)

Enter that directory (in this example we assume the current user is root):

$ cd /var/opt/gitlab/git-data/repositories/root
$ pwd
/var/opt/gitlab/git-data/repositories/root
$ ls
kafka.git  kafka.wiki.git

Configure

$ subgit configure https://svn.apache.org/repos/asf/kafka kafka.git
...
Git repository is served by GitLab, hooks will be installed into 'custom_hooks' directory.

CONFIGURATION SUCCESSFUL
...

Make sure you see the line

Git repository is served by GitLab, hooks will be installed into 'custom_hooks' directory.

This means that SubGit has detected GitLab presence and generated

[hooks]
        directory = custom_hooks

option in subgit/config file of the Git repository. This option means that SubGit will work with custom_hooks directory instead of hooks directory to install/uninstall/upgrade hooks. This is important because hooks directory is reserved by GitLab for its own purposes.

Above mentioned “subgit configure” command expects that the SVN URL has trunk/branches/tags structure.

up

2.4 Adjust general configuration, authentication configuration, and authors mapping

Edit subgit/passwd to provide credentials for the SVN repository.

$ vi /var/opt/gitlab/git-data/repositories/root/kafka.git/subgit/passwd

Edit subgit/authors.txt to provide mapping between SVN authors and Git authors.

$ vi /var/opt/gitlab/git-data/repositories/root/kafka.git/subgit/authors.txt

Edit subgit/config according to your needs. See comments in subgit/config files for details.

$ vi /var/opt/gitlab/git-data/repositories/root/kafka.git/subgit/config

up

2.5 Start synchronization

Now everything is ready for starting synchronization of the Git repository with the SVN repository. To start the process run

$ subgit install kafka.git

First it will run initial translation of the SVN repository to Git. On the command completion, SubGit will start a daemon that will translate every change in the SVN repository to kafka.git repository and vice versa.

up