jwm
jwm

Reputation: 1844

git-svn merging when branches don't line up

I suspect this may simply be an impedance mismatch between git and svn, but I wanted to ask the SO community for advice.

I am working on a project that uses svn for version control. That's not going to change, and I have no control over it. I've happily been doing my work on my branch using git-svn. However, I ran into an odd problem related to the strange way the SVN project was set up.

In SVN, the project looks like this:

.git/config:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[svn-remote "svn"]
    url = http://svn-repo
    fetch = project/trunk:refs/remotes/trunk
    branches = project/branches/*:refs/remotes/*
    tags = project/tags/*:refs/remotes/tags/*

When the branches were created, they were created one level below trunk. I had no control over this either.

When I try to merge from MyBranch to trunk, my tree merges one level up. That is, MyBranch/Dir1 has no relationship to trunk/Proj_Main/Dir1. In svn natively, it does understand this relationship, and I can merge using svn tools, but git is lost.

Is there a way I can tell git that master points to trunk/Proj_Main instead of just trunk?

Upvotes: 0

Views: 25

Answers (2)

jwm
jwm

Reputation: 1844

@eftshift0 had the right approach. Sometimes there is no salvaging a bad situation. I made sure everything was sync'd with SVN and started over again.

git svn clone -r<start>:HEAD http://svn-repo/project \
    --prefix=mine/ \
    --trunk=trunk/Proj_Main --branches=branches --tags=tags \
    --no-minimize-url

Since this is a very mature SVN repo, and I don't care about history from 5 years ago, I limited the scope of my clone, for the sake of time.

The --prefix is based on advice in the git-svn docs.

Rather than -s or --stdlayout, I explicitly specified how things were laid out in SVN. Note that early attempts to apply this approach encountered a git-svn bug fetching, probably related to a deleted SVN branch. That's another reason for limiting the scope of the fetch.

The --no-minimize-url is due to the fact that other repos exist at the server. Without this switch, git-svn pushes up a level and considers all the repos in trying to resolve branches, merges, and such. That was not a good thing for me.

Upvotes: 0

eftshift0
eftshift0

Reputation: 30166

Edit the fetch line to something like:

fetch = project/trunk/Proj_Main:refs/remotes/trunk

That should do.... however, I don't know if you will have to fetch again from revision 1 for such a change to work correctly.

Upvotes: 2

Related Questions