3

I want to clone a SVN tree into a git repo using git-svn. I'd like to make a complete clone, including tags and branches, but I hit a problem with the tags organization.

the SVN tags folder looks like this:

tags/
|-- Backup
|   |-- 20080212
|   `-- 20080217
|-- V4.0.1
|-- V4.0.2
`-- V4.0.3

I know about git svn clone -T trunk -b branches -t tags/Backup -t tags with twice the -t option, but this is not entirely satisfying:

$ git branch -r
  tags/20080212
  tags/20080217
  tags/Backup
  tags/V4.0.1
  tags/V4.0.2
  tags/V4.0.3
  trunk

As you can see, all the tags are here, but one is too much: the Backup tag is actually not a tag but a folder containing tags. The problem is that it creates an orphan branch which duplicate the content of all the backup branches.

The question is: How do I make git-svn ignore the backup folder but know about the backup subfolders as tags, keeping the classical tags available?

And as a bonus: how to automatically name the Backup tags as Backup/20080217 instead of 20080217?

Thanks!

CJlano
  • 1,532
  • 1
  • 12
  • 18

2 Answers2

3

git svn isn't intelligent enough to be able to ignore the Backup folder in one group of tags but include its subfolders. You've a bunch of options, none of which are great:

  • Change the underlying Subversion repository to move all the tags into subfolders, so your repository looks something like this:

    tags/
    |--Backup/
    |  |--20080212
    |  `--20080217
    `--Versions/
       |--V4.0.1
       |--V4.0.2
       `--V4.0.3
    

    You can then use -t tags/Backup -t tags/Versions to pick up all the tags.

  • Cope. While irritating, the way Git manages tree objects means having a "Backup" tag won't actually take any more space or slow down most Git operations; the only impact will be git svn fetches will take longer.

  • Write your own patch for git-svn to enable handling this scenario. Bonus points if you get it included in future official Git releases.

Getting the tags to have a different name is fairly easy, at least. If you edit your .git/config file, you should find a line that looks something like this:

tags = tags/Backup/*:refs/remotes/tags/*

You should be able to change this to the below instead:

tags = tags/Backup/*:refs/remotes/tags/Backup/*

If you do this between running git svn init and the first git svn fetch, everything should just work. Otherwise, you may need to manually remove the old references first, by deleting any files or folders with a name matching the tag name in .git/logs/refs/remotes/tags/, .git/svn/refs/remotes/tags/ and .git/refs/remotes/tags.

I have no idea what will happen if you have a tag called "Backup" and a folder of tags called "Backup", though. I suspect nothing good. You'll need to find some way of avoiding that, or store the Backup tags in a folder with a different name.

me_and
  • 15,158
  • 7
  • 59
  • 96
  • Thanks for the long answer. Renaming the tags fails as you describe it with the following: `error: unable to create directory for .git/refs/remotes/tags/Backup/20080212 fatal: Cannot lock the ref 'refs/remotes/tags/Backup/20080212'. update-ref -m r175 refs/remotes/tags/Backup/20080212 b1aa4898486b123aa6c270e657ee49ffbd8ed3ad: command returned error: 128` – CJlano Feb 29 '12 at 21:43
  • 1
    Can you tell me the result of `file .git/refs/remotes/tags/Backup`? If that comes up as something other than "directory", it means it can't create the folder called "Backup" because there's already a tag with that name. As I said in the last paragraph, I'd give that folder a different name to avoid that clash; possibly use `tags = tags/Backup/*:refs/remotes/tags/bkutags/*` or similar in place of the config line I suggested in the question. – me_and Mar 01 '12 at 10:56
0

Use SmartGit to clone the repository, it creates correct tags, provides better translation and works faster than git-svn.

Dmitry Pavlenko
  • 8,530
  • 3
  • 30
  • 38