Mr_and_Mrs_D
Mr_and_Mrs_D

Reputation: 34026

git svn specify branches and tags on a non standard svn repository layout

The layout is :

Branches\
    Project1/
        Branch11/
        ...
        Branch1N/
    Project2/
        Branch21/
    ProjectX/   # not anywhere else
Excluded1\
Excluded2\
Excluded3\
Excluded4\
Programs\
    Excluded11\
    ...
    Excluded1N\
    Project1/   # the main one
    Project2/
    ...
    ProjectN/
Tags\
    Project1/
        Release1/
        ...
        Release69/

Excluded I managed to exclude - but I am completely unable to understand how can I map branches/tags to git branches/tags - preferably after the fact (each clone takes ~5 hours).

Please bear in mind I am new to SVN - I know not nor do I understand the branching/tagging system.

I am on windoz - svn2git is no option (anyway I am interested in how I do this after the clone or at worse cloning again but with vanilla git only)
Also I do not intend this as a permanent migration, it will function as a bridge between the SVN and the new git repo used in dev - so I want to keep as much info as possible - but no more than needed. At some point it might become permanent - where upon I will need to filter out empty commits (to the excluded projects) I guess (?)

Repo

Command :

$ git svn clone --ignore-paths="^(?:Releases|Projects|Scripts|Games|)/|^Programs/(?:Nif Scanner|Nif Viewer|Raziel23x's Oblivion Toolset|Shader Disasm|Shader Editor)/" --authors-file=authors_with_emails.txt svn://svn.code.sf.net/p/oblivionworks/code/ .

After the clone I have :

$ git branch -r
  git-svn
$ git branch
* master


Recap : I have cloned the thing excluding what I wanted to exclude - now I want to say to git "create a git branch for each of those svn branches - a real git branch that calculates the deltas and compresses them and deletes the folder Branches - and track them - and this (700 mb) tags directory is just tags - what could you do about that (they do not correspond to commits) ?"
I see no evil trunk

My config :

[core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
    hideDotFiles = dotGitOnly
[svn-remote "svn"]
    ignore-paths = ^(?:Releases|Projects|Scripts|Games|)/|^Programs/(?:Nif Scanner|Nif Viewer|Raziel23x's Oblivion Toolset|Shader Disasm|Shader Editor)/
    url = svn://svn.code.sf.net/p/oblivionworks/code
    fetch = :refs/remotes/git-svn
[svn]
    authorsfile = authors_with_emails.txt
[gui]
    wmstate = zoomed
    geometry = 787x377+54+59 305 1127
[remote "github"]
    url = https://github.com/Utumno/wrye_bash_refactoring.git
    fetch = +refs/heads/*:refs/remotes/github/*
[branch "master"]
    remote = github
    merge = refs/heads/master

Upvotes: 3

Views: 4355

Answers (2)

Steven Collins
Steven Collins

Reputation: 147

I did something like this recently.

First of all, I'm not sure why you want to rearrange everything after moving out of svn into git. I doubt that's possible.

Second, I wouldn't dream of doing this without svn2git. I'm not sure what the Windows problem is you're referring to - svn2git is written in Ruby. I don't do Windows if I can avoid it, but surely there's a Ruby implementation for Windows, through Cygwin if nothing else.

Third, and this was the key, I used svndumpfilter to get the svn repo just the way I wanted it (i.e., in a form that svn2git would happily consume) before converting. This took some trial and error but it worked really well in the end.

See http://svnbook.red-bean.com/en/1.7/svn.reposadmin.maint.html#svn.reposadmin.maint.migrate and http://svnbook.red-bean.com/en/1.7/svn.reposadmin.maint.html#svn.reposadmin.maint.filtering (adjust links for your SVN version) for more info.

EDIT: I would have made this a comment but it's too long. I think the best you'll be able to do is something like this:

[svn-remote "svn"]
    ignore-paths = ^(?:Releases|Projects|Scripts|Games|)/|^Programs/(?:Nif Scanner|Nif Viewer|Raziel23x's Oblivion Toolset|Shader Disasm|Shader Editor)/
    url = svn://svn.code.sf.net/p/oblivionworks/code
    fetch = Programs/Wrye Bash:refs/remotes/git-svn/Wrye Bash
    branches = Branches/Wrye Bash/*:refs/remotes/git-svn/Wrye Bash/branches/*
    fetch = Programs/Skyrim Viewer:refs/remotes/git-svn/Skyrim Viewer
    fetch = Programs/CBash:refs/remotes/git-svn/CBash
    branches = Branches/CBash/*:refs/remotes/git-svn/CBash/branches/*
# etc.

That is, a fetch, and, if applicable, a branches line for each program you're interested in. Like in the answer you linked to, you'd have to purge the .git/svn/.metadata file before doing git svn fetch again.

But this does nothing to affect my earlier comment: it is still the case that your git history is completely linear and does not reflect the actual branching and merging history of your project. This will not be what you want if you make this a permanent migration.

Upvotes: 1

Michael
Michael

Reputation: 10474

For Branches:

In your git config file you can control where the svn branches are located:

[svn-remote "svn"]
url = file:///some.url.to/svn/dir
fetch = trunk:refs/remotes/trunk
branches = Branches/*/*:refs/remotes/*

So you are able to setup the different references to the branches.

OK so you can do the same for tags - cause in svn, tags and branches are so similar.

branches = Tags/*:refs/remotes/*

But you want "real" git tags, no problem, once you have them referenced as branches, you can modify your git repo again to make good git tag references:

git-for-each-ref refs/remotes/origin/tags | cut -d / -f 5- |
while read ref
do
git tag -a "$ref" -m"say farewell to SVN" "refs/remotes/origin/tags/$ref"
git push origin ":refs/heads/tags/$ref"
git push origin tag "$ref"
done

Obviously, you will need to slightly modify these scripts for your purposes.

Upvotes: 2

Related Questions