SubGit: How to exclude branches?
Asked Answered
V

1

7

I'm testing SubGit as a way of migrating from SVN to Git.

What I would like to do is be able to create remote branches in the git repository that all users can use that does not sync back to SVN.

I only want SubGit to track the master branch and sync it back to SVN so that we have the freedom to use and share other Git branches.

Is there a simple way to do this?

Thank you

Vines answered 16/5, 2013 at 13:2 Comment(0)
S
8

The ideal solution would be specifying trunk:refs/heads/master mapping in SubGit configuration, so SubGit would synchronize trunk with master ignoring any other branches.

Unfortunately, SubGit needs at least one branches mapping at the moment (versions 1.0.x and 2.0.x). That is, one has to specify something like this:

trunk = trunk:refs/heads/master
branches = branches/*:refs/heads/*
shelves = shelves/*:refs/shelves/*
tags = tags/*:refs/tags/*

Since you're not going to synchronize all the Git branches, consider using some special namespace to workaround the issue:

trunk = trunk:refs/heads/master
branches = branches/*:refs/gitsvn/heads/*
...

So, if one pushes master branch to central Git repository, it gets translated to trunk. However, if one pushes branch foo, SubGit ignores that branch since refs/heads/foo is out of sync scope.

The troubles come from merge commits: if commit A is the result of merging branch foo into master, then SubGit creates branches/foo on Subversion side for corresponding parent of commit A. If you'd prefer to not include SubGit generated branches into *branches/** namespace, consider using some special branches on Subversion side as well:

trunk = trunk:refs/heads/master
branches = gitsvn/branches/*:refs/gitsvn/heads/*
shelves = shelves/*:refs/shelves/*
tags = gitsvn/tags/*:refs/gitsvn/tags/*

In this case the same parent of commit A should be sent to gitsvn/branches/foo branch.

This is the best solution available at the moment. We also have a feature request for version 2.1 that would enable an ideal solution for you, but it's going to take some time before we implement it.

Update on SubGit 3.0:

Since version 3.0.0 (early access stage at the moment, download at http://subgit.com/eap) SubGit supports single branch layout, so configuration file may look as follows:

  1. No trunk, no branches, no tags and no shelves:

    [svn]
        url = http://host.com/repos/project
    

    In this case, project directory is mapped directly to master branch in Git repository; SubGit ignores any other branches and never creates shelves which mean anonymous Git branches don't get synced to SVN.

  2. Single trunk, no shelves:

    [svn]
        url = http://host.com/repos/project
        trunk = trunk:refs/heads/master
    

    In this case, project/trunk directory is mapped to master branch in Git repository; SubGit ignores any other branches and never creates shelves.

  3. Single trunk with shelves:

    [svn]
        url = http://host.com/repos/project
        trunk = trunk:refs/heads/master
        shelves = shelves/*:refs/shelves/*
    

    In this case, project/trunk directory is mapped to master branch in Git repository; SubGit ignore any other branches but it translates anonymous branches to shelves as by default for versions 1.0.x and 2.0.x.

Hope that helps.

Sixtieth answered 16/5, 2013 at 15:17 Comment(7)
Thank you for the reply. I've been playing about with it in the meantime and came up with putting all my git-only branches (such as foo) into a separate remote bare repository and then merging foo into master when necessary and then push things back into the synchronization repositoryVines
How is it going with the mentioned ideal solution? I opened a new question related to this one, since I would like to have git branches NEVER reflected into svn. ThanksMetheglin
It's still work in progress. Such layout is fully supported in svn-to-git direction, but there are certain edge cases we have to deal with while converting Git commits to SVN revisions. Anyway this feature is in the top of our priority list at the moment.Sixtieth
Is there a link to ticket you could provide as I would be very interested in this feature as well.Tout
@JonCage Please see the update I just submitted. In version 3.0 we introduced extremely flexible layout support, so one can use one single branch mapping for the mirror or have something like branches/1.2.*/*:refs/heads/1.2.x/*/* and much more. We're in the progress of updating documentation on new features, for more details feel free to contact us at [email protected] or ask more questions here on stackoverflow.Sixtieth
When I initially created a subgit repo for svn-git syncing, I created it with branches and shelves added in the config. After a while I realized that setup doesn't work for me and I've just commented out the branches and the shelves - but the syncing for them still happens (on push to SVN). Is it maybe so that the config is read and remembered only at the initial repo set up?Dunois
@Dunois It is not possible to update branches mapping for a Git repository where SubGit is already installed. The easiest way would be to reinstall SubGit following standard configuration stages. For more information visit here.Zug

© 2022 - 2024 — McMap. All rights reserved.