How to access svn branches using git-svn with custom svn repository layout?

The standard repo layout in svn is as follows.

/trunk /branches featureX featureY /tags 1.0 2.0 

The repository I'm working with is a much denser structure.

 trunk featureX featureY 

Essentially, the trunk is at the same level as the other branches. Because of this, I cannot use the -s or -b option with git svn init .

How can I insert trunk as a git master branch and insert featureX as a git branch with the same name? I do not need any other branches or tags.

I saw similar questions, and people suggested restructuring the svn repository. This relates to a question regarding this issue.

+4
source share
2 answers

I figured out a way to infer multiple branches from an arbitrary svn repository structure.

The -b for git svn init will work only if all branches are grouped together in a subdirectory in the repository, for example, in a standard layout. If all branches, including the trunk, are located nearby in the same folder, this will not work. You can pull the selected branches from the svn repository, essentially creating a few "trunks" in your git repository.

Suppose a flat question structure is associated with three branch branches, featureX and featureY.

  • Create an instance of your git repository.

     mkdir myproject cd myproject git svn init url:to/svn/repo -T trunk 

    This will create a git repository with svn metadata in the .git/config file.

  • Open the configuration file and check svn metadata

     vim .git/config 

    Your configuration file will look something like this.

     [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true autocrlf = false [svn-remote "svn"] url = url:to/svn/repo fetch = trunk:refs/remotes/trunk 

    The svn-remote header defines a link called "svn" that points to your svn repository. The fetch parameter tells git-svn where to get the new revisions from the svn repository. Now we need to tell git-svn about another branch of interest to us.

  • Duplicate the svn-remote section

    Copy the entire svn-remote section of the configuration file and paste it below the existing configuration text.

     [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true autocrlf = false [svn-remote "svn"] url = url:to/svn/repo fetch = trunk:refs/remotes/trunk [svn-remote "svn"] url = url:to/svn/repo fetch = trunk:refs/remotes/trunk 
  • Change the new svn-remote partition

    Change the name of the svn-remote section header and the name of the branch it points to.

     [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true autocrlf = false [svn-remote "svn"] url = url:to/svn/repo fetch = trunk:refs/remotes/trunk [svn-remote "svn-featureX"] url = url:to/svn/repo fetch = featureX:refs/remotes/featureX 

    Now git-svn will track both branches of svn. You can use the names "svn" and "svn-featureX" with any git [svn-remote] that accepts the [svn-remote] parameter. You can use the names "trunk" and "featureX" with any git command that takes the name of the remote branch as a parameter.

This solution will not scale well and hack a little work with the wrong svn repository. As long as you only need to track multiple svn branches, this will work just fine. If the number of svn branches you need to work with becomes too large, take a serious look at restructuring your svn repository into a standard layout.

+3
source

As shown in the article, you can write rules to run the importer, for example
(you have a less full version of svn2git here )

See these examples for rules you could rewrite to map these flat SVN directories / branches and declare them as Git branches.

+1
source

All Articles