gitsvnversion-controltrac

Can I migrate trac from SVN to Git repositories without exporting + creating a new trac instance?


We think about migrating from SVN to Git and since trac supports both, can we just change the address of the repository to use Git? All the documentation I found was between two instances of SVN.

If it isn't that simple, which steps are required to migrate the data from wiki and tickets? I have found a script for changing the references in tickets to the hash equivalent of Git, but that would come after I guess.

Thanks in advance


Solution

  • Yes, you can connect Trac to a Git repository without recreating the environment. Adding repositories to an existing environment is a common operation, and Trac supports multiple repositories, provided you are using Trac 0.12 or later. I'll assume you are using Trac 0.12 or later.

    If you are using Trac 0.12 or later and have already defined your repository configuration through the [repositories] section of trac.ini or using the repository admin page /admin/versioncontrol/repository, you can simply modify the configuration to change the repository path and type. Make sure you've enabled the optional Git connector in the [components] section of trac.ini: tracopt.versioncontrol.git.* = enabled.

    However, if you have previously used a version of Trac < 0.12, it could be more complicated. Prior to Trac 0.12 only a single repository was supported and it was specified in the [trac] repository_dir option. If your configuration still uses this option, you should update your configuration to use the [repositories] section of trac.ini. If you upgrade to Trac 1.2 or later this should happen automatically when the trac-admin upgrade command is executed to upgrade the environment (see TracUpgrade).

    The repositories in the [repositories] section are defined using the syntax name.attribute = value. The name is whatever name you give to the repository. If the name is omitted, then you are referring to the default repository (syntax is .attribute = value). The required attributes are path and type (technically type may not be required because there is also a "default type", but for simplicity just assume it is required).

    If you old configuration looks like this:

    [trac]
    repository_dir = /path/to/repo/1
    repository_type = svn
    

    Your new configuration would be:

    [repositories]
    .dir = /path/to/svn/repo
    .type = svn
    

    You could change type to git if you will no longer have your SVN repository connected to Trac. However, a common scenario is to leave the old SVN repository connected to Trac so that TracLinks to the repository continue to function (e.g. changeset links like [1] or r1), and add a second repository. In that case, your configuration might be:

    [repositories]
    .dir = /path/to/svn/repo
    .type = svn
    git-repo.dir = /path/to/git/repo
    git-repo.type = git
    

    The TracLinks syntax for referring to a named repository in a multi-repository environment differs from the syntax for referring to the default repository. See examples here.

    Alternative to the [repositories] section of trac.ini, you can configure the repositories through the repository admin page (admin/versioncontrol/repository).

    More information can be found on the TracRepositoryAdmin page.