I've figured out a way to pull in multiple branches from an arbitrary svn repository structure.
The -b
option for git svn init
will only work if all branches are grouped together within a subdirectory in the repository, such as in the standard layout. If all branches, including the trunk, are side by side in the same folder, this won't really work. You can pull in selected branches from the svn repository by essentially creating multiple "trunks" int your git repository.
Assume the flat structure from the question with the three branches trunk, featureX, and featureY.
Instantiate 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 config file and examine the svn metadata
vim .git/config
Your config 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 reference called "svn" pointing to your svn repository. The fetch
parameter tells git-svn where to pull new revisions from within the svn repository. Now we need to tell git-svn about the other branch we're interested in.
Duplicate the svn-remote
section
Copy the entire svn-remote
section of the config file and paste it below the existing config 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
Modify the new svn-remote
section
Change the name of the svn-remote
section header and the name of the branch that 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 svn branches. You can use the names "svn" and "svn-featureX" with any git-svn command that takes an [svn-remote]
parameter. You can use the names "trunk" and "featureX" with any git command that takes a remote branch name as a parameter.
This solution won't scale well, and is a bit of a hack to work with a malformed svn repository. So long as you only need to track a handful of 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 to the standard layout.