18

I'm using git-svn to work with a svn repo. I don't want the whole repo, sine it contains a lot of legacy, with binaries in it. I'm only tracking some directories.

Here is my current .git/config, which is working fine.

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[svn-remote "svn"]
    url = https://svn.example.com/repository
    fetch = trunk/Python:refs/remotes/trunk
    branches = branches/{stage,prod,stage_with_proxy}/ucapi/:refs/remotes/*
    branches = branches/{active}/Python/:refs/remotes/*

Now I want to add a new branch:

    branches = branches/{fuze_node}/:refs/remotes/*

but when doing git svn fetch the new branch is not visible to git. It acts as if the line is not in the config.


I know this could be done with a new svn-remote, but I would prefer not to take that road.

Emil Ivanov
  • 37,300
  • 12
  • 75
  • 90
  • 1
    Did you try a `git svn fetch --all`or a `git svn fetch --all -r 10000:HEAD`? (after http://stackoverflow.com/a/9240692/6309). Or another `git-svn clone --fetch-all` to see if that other clone would get *all* the branches? – VonC Nov 17 '12 at 21:54
  • I tried `fetch --all`. Haven't tried `clone`, since this would take about 2 days (lots of history, svn server on the other side of the planet) and don't want to do a `clone` every time I need to add a branch. – Emil Ivanov Nov 18 '12 at 12:49

2 Answers2

23

For every svn-remote git-svn stores the latest fetched revision in .git/svn/.metadata file. It never fetches revisions less than that value. That's why it doesn't fetch the branch you've added to config; git-svn thinks fuze_node branch is already converted.

However you can fetch this branch without re-cloning the whole repository once again:

  1. Add another svn-remote with all the branches you need to fetch;
  2. Remove the older svn-remote;
  3. Run git svn fetch -R newer-svn-remote to fetch revisions from the added branch.

Your config should look like this:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
# [svn-remote "svn"]
#    url = https://svn.example.com/repository
#    fetch = trunk/Python:refs/remotes/trunk
#    branches = branches/{stage,prod,stage_with_proxy}/ucapi/:refs/remotes/*
#    branches = branches/{active}/Python/:refs/remotes/*
[svn-remote "newer-svn-remote"]
    url = https://svn.example.com/repository
    fetch = trunk/Python:refs/remotes/trunk
    branches = branches/{stage,prod,stage_with_proxy}/ucapi/:refs/remotes/*
    branches = branches/{active}/Python/:refs/remotes/*
    branches = branches/{fuze_node}/:refs/remotes/*

Note that you have to specify exactly the same branches mapping as in the older svn-remote:

    branches = branches/{stage,prod,stage_with_proxy}/ucapi/:refs/remotes/*

That is, refs/remotes/* should still be on the right side of the mappings. Otherwise git-svn fails to detect already converted commits and tries to fetch them once again.


There's actually another way to achieve the same. It involves some manipulations with internal git-svn files though.

You can just add necessary branch to .git/config and update .git/svn/.metadata file, so the latest fetched revision becomes 0:

[svn-remote "svn"]
    reposRoot = https://svn.example.com/repository
    uuid = 8a6ef855-a4ab-4527-adea-27b4edd9acb6
    branches-maxRev = 0
    tags-maxRev = 0

After that git svn fetch will fetch only necessary revisions.

vadishev
  • 2,979
  • 20
  • 28
0

I've found a much easier method, which does not require editing any config files.

You only need the revision number of the last commit in the branch that you want to add to your local git-svn repository.

If you have a SVN checkout of the new branch and TortoiseSVN installed, you can right-click on this folder and use "TortoiseSVN / Show Log".

Make a note of the topmost commit (e.g. 45065).

Now use in Git Bash the following command:

git svn fetch -r45065

NOTE: You need to replace the number 45065 against your commit number.
git will now pull the new remote branch into your local repository.

You can then check it out with creating a local Branch. I'm using Git Extension for checking out the new branch, using "Remote-Branch" and the option "Create local branch with name: ...".
Hint: You can remove the "origin/" prefix from your local branch name, as this avoids the warning "refname 'origin/V8.0' is ambiguous.".

Dirksche
  • 21
  • 3