Migrating a subdir from Google Code SVN to Drupal Git
There are several SVN users out there who use one single monolithic repo for multiple projects. Let's assume you are maintaing Drupal module [yourmodule] in Google Code SVN repo under trunk/path/to/[yourmodule]. How to migrate only that particular subdirectory to Drupal Git?
There are many ways to solve it, I am going through options A (simpler, slower) and B (complex, faster).
Option A: Git Way
This option is more Git-centric and simpler but could be a slower if you have a massive SVN repo since we are cloning the whole shebang first.
Step A1: Convert a full Google Code SVN repo to local Git repo
git svn clone -s http://[your_google_code_repo].googlecode.com/svn [yourmodule]
Optionally you may want to convert the commiter's usernames to Drupal usernames. To do that, create a file authors.txt and fill it with following
[google_code_username] = [drupal_org_username]<[drupal_org_email]> …
In my personal case some strange commits had no author, so I had to add following line as well
(no author) = [drupal_org_username] <[drupal_org_email]>
so the command above looks like this instead
git svn clone –authors-file=path/to/authors.txt -s http://[your_google_code_repo].googlecode.com/svn [yourmodule]
Step A2: Get rid of everything inside local Git repo except your module
cd [yourmodule] git filter-branch –subdirectory-filter [path/to/yourmodule] HEAD git reset –hard git gc –aggressive git prune
Optionally you may want to get rid of git-svn-id's what git svn clone has added to each commit message: "git-svn-id: file:///local/path/to/[mymodule]_svn/trunk@[rev] [hash]"
To get rid of this, follow these instructions. To summarize: git clone this https://github.com/…-svn-abandon, make sure the directory is accessible from $PATH and inside your git repo run
git svn-abandon-cleanup
Surprisingly I had to run this command twice to get the desired effect.
Step A3: Push local Git repo to Drupal.org
Make sure you have set up git access, keys and new project [yourmodule] first (for testing create a sandbox project).
git remote add origin [drupal_git_username]@git.drupal.org:project/[mymodule].git git push origin master
Ta-da, you successfully moved a subdir from Google Code SVN to Drupal Git!
Option B: SVN Way
This might be a little quicker option if you have a gigantic Google Code SVN repo but it's a bit messier to get going.
Step B1: Create local SVN repo
svnadmin create [yourmodule]_svn
(the "_svn" suffix is arbitrary, it's there to separate directory name from future git repo directory)
then run your favourite text editor
mate [yourmodule]_svn/hooks/code-revprop-change
fill it with following contents and save:
#!/bin/bash exit 0
Then run
chmod +x [yourmodule]_svn/hooks/code-revprop-change
Step B2: Sync a subdirectory from Google Code SVN to local SVN repo
svnsync init –username [google_code_username] file:///[local/path/to/][yourmodule]_svn https://[your_google_code_repo].googlecode.com/svn/[path/to/][yourmodule]
and then (this might take a while)
svnsync sync –username [google_code_username] file:///[local/path/to/][yourmodule]_svn
Step B3: Convert local SVN repo to local Git repo
git svn clone -s file:///[local/path/to/][yourmodule]_svn [yourmodule]
As in Step A1 you may want to use authors.txt in this command and as in Step A2 use "git svn-abandon-cleanup" afterwards.
Step B4: Push local Git repo to Drupal.org
You will know the drill:
cd [yourmodule] git remote add origin [drupal_git_username]@git.drupal.org:project/[mymodule].git git push origin master
Note that my personal case was simple: I had no branches nor tags in my Google code repo so I have not tested those more complicated cases. Looking forward for feedback how to do the migration per branch/tag.
References:
http://code.google.com/…ubversionFAQ HowdoIdownloadmySubversionhistory?
http://help.github.com/svn-importing/