1
votes

Background:

Our team needs to connect to an svn server and work on a particular branch (not the svn trunk). On top, we need to also get the trunk and merge between them.

I have set up a local git repository connected to our branch ("svn+ssh...project/branches/X").

Then, I have manually added the trunk as a new svn connection ("svn+ssh...project/trunk") (I added a new remote target for the svn trunk, to .git/config) and renamed my branches as follows:

master (connected to project/branches/X) was renamed to master-X

the branch connected to project/trunk was renamed to master-trunk.

Question:

When I git svn dcommit on the master-X local branch, a new 'master' branch is created, with the same effect as if I did:

git svn dcommit
git co master-X -b master

Can I prevent the master branch from being recreated?

(every time it is created I delete it manually afterwards).

Edit:

My .git/config now looks like this:

# original/default configuration settings skipped for brevity

[svn-remote "svn"]
    url = svn+ssh://...project/branches/X
    fetch = :refs/remotes/git-svn

[svn-remote "svn-trunk"]
    url = svn+ssh://...project/trunk
    fetch = :refs/remotes/git-svn-trunk

The last three lines were added by me.

1

1 Answers

1
votes

This is old Git behaviour, that has been fixed in recent Git releases. Anything more recent than Git 1.7.12 will no longer automatically recreate a master branch. You can run git --version to get the version of Git you're currently running.

That's not much use if the version that comes with your operating system is earlier than 1.7.12 (the latest I have easy access to, between my Debian, RHEL and Cygwin systems, is 1.7.9).

If you want to, you should be able to make the change yourself, however. Find the copy of git-svn or git-svn.perl on your system (on mine, it's /usr/lib/git-core/git-svn), then make the following changes:

  • Below Git::SVN::init_vars(), move the post_fetch_checkout(); line to before the closing brace, so that bit of code looks like so:

    Git::SVN::init_vars();
    eval {
            Git::SVN::verify_remotes_sanity();
            $cmd{$cmd}->[0]->(@ARGV);
            post_fetch_checkout();
    };
    fatal $@ if $@;
    exit 0;
    
  • In the post_fetch_checkout subroutine…

    • Add the following line above the line starting my $gs =:

      return if verify_ref('HEAD^0');
      
    • Delete the line that reads like so:

      return if verify_ref('refs/heads/master^0')
      
    • Replace the following lines:

      my $valid_head = verify_ref('HEAD^0');
      command_noisy(qw(update-ref refs/heads/master), $gs->refname);
      return if ($valid_head || !verify_ref('HEAD^0'));
      

      with the following:

      command_noisy(qw(update-ref HEAD), $gs->refname);
      return unless verify_ref('HEAD^0);
      

The above changes will apply the patch that changed this behaviour in the Git source code. You can see that for yourself: the relevant commit is v1.7.11.2-250-ge3bd4dd by Marcin Owsiany.