Igor Brito Alves
Igor Brito Alves

Reputation: 68

git-svn: Migrating a SVN repository with branches in different hierarchical levels

I'm migrating a lot of Git repositories in my company and everything was fine until I faced a repository with a very specific layout for branches:

/trunk/
/branches/
/branches/lvl1branch1
/branches/lvl1branch2
/branches/lvl1branch3
/branches/lvl2/lvl2branch1
/branches/lvl2/lvl2branch2
/branches/lvl2/lvl2branch
/branches/lvl2/lvl3/lvl3branch1
/branches/lvl2/lvl3/lvl3branch2
/branches/lvl2/lvl3/lvl3branch3
/tags/

As you can see, we have branches not only in the top level of /branches/ (e.g. lvl1branch1), but only in other two levels (e.g. lvl2/lvl2branch1 and lvl2/lvl3/lvl3branch3).

This is my .git/config:

[core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
[svn-remote "svn"]
    url = https://myrepourl/
    fetch = test/trunk:refs/remotes/origin/trunk
    branches = test/branches/*:refs/remotes/origin/*
    branches = test/branches/lvl2/*:refs/remotes/origin/lvl2/*
    branches = test/branches/lvl2/*/*:refs/remotes/origin/lvl2/*/*

And I get this error when I try to run the git svn fetch command:

fatal: update_ref failed for ref 'refs/remotes/origin/lvl2/lvl3/lvl3branch1': cannot lock ref 'refs/remotes/origin/lvl2/lvl3/lvl3branch1': 'refs/remotes/origin/lvl2/lvl3' exists; cannot create 'refs/remotes/origin/lvl2/lvl3/lvl3branch1' update-ref -m r1638 refs/remotes/origin/lvl2/lvl3/lvl3branch1 e421f7d976832aa2efe84da02378e7f89eb55c26: command returned error: 128

I can see I can create the branch lvl2/lvl3/lvl3branch1 because Git is considering lvl2/lvl3 is a branch, which is not true. Probably the line below in .git/config is causing the problem:

branches = test/branches/RT-Delivery/*:refs/remotes/origin/lvl2/*

How can I tell Git to avoid reading lvl2/lvl3 as a branch? I believe I will also face the same problem with lvl2, which is not a branch. Is there a way to add exceptions?

Upvotes: 2

Views: 168

Answers (1)

Igor Brito Alves
Igor Brito Alves

Reputation: 68

I found out a solution, we can use the wildcards (*) also for filtering the directory names. Here is the .git/config:

[core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
[svn-remote "svn"]
    url = https://svn.it.volvo.net/svn/rtdms_tools/
    fetch = test/trunk:refs/remotes/origin/trunk
    branches = test/branches/lvl1*:refs/remotes/origin/*
    branches = test/branches/lvl2/lvl2*:refs/remotes/origin/lvl2/*
    branches = test/branches/lvl2/lvl3/*:refs/remotes/origin/lvl2/lvl3/*

For instance, in order to make sure we will only get the branches in the first level (the ones starting with "lvl1"), instead of

branches = test/branches/*:refs/remotes/origin/*

we can use

branches = test/branches/lvl1*:refs/remotes/origin/*

Upvotes: 2

Related Questions