As a follow up to last post about setting up git with gitorious
Here are the steps to mirror a git branch into svn.
First, I had to install git-svn
$ sudo port deactivate git-core $ sudo port install git-core +svn
That did not got so well when trying to run git-svn:
error about Error.pm: Can't locate Error.pm in @INC (@INC contains...
Something did not get copied correctly. Here’s the solution:
$ cp /opt/local/var/macports/software/git-core/1.5.2.4_1+doc/opt/local/lib/perl5/site_perl/5.8.8/Error.pm /opt/local/lib/perl5/site_perl/5.8.8/
Then create a place holder in svn so a location exist (it’s fine if it is empty):
$ svn mkdir svn+ssh://svn.nanorails.com/home/psq/svn/plugins/plugins/rur -m "creating rur"
Then add this to .git/config:
[svn-remote "nanorails"] url = svn+ssh://svn.nanorails.com/home/psq/svn/plugins/plugins/rur fetch = :refs/remotes/nanorails
nanorails will become the name of the branch
Then fetch the svn (it won’t fetch anything, but this starts the process).
$ git svn fetch nanorails $ git branch -a * master nanorails
And the new branch is here :)
Checkout that svn branch into a local branch:
$ git checkout -b local-svn nanorails Switched to a new branch "local-svn" $ git branch -a * local-svn master nanorails
Now the fun part.
Using rebase will forward the local commits to the updated upstream head
$ git-svn rebase Current branch local-svn is up to date.
Get all the goodies from the master branch
$ git merge master Merge made by recursive. .gitignore | 1 + MIT-LICENSE | 21 ++ README | 48 +++++ Rakefile | 20 ++ init.rb | 3 + lib/undo_action.rb | 24 +++ lib/undo_manager.rb | 89 ++++++++ lib/undo_record.rb | 224 ++++++++++++++++++++ lib/undoable.rb | 40 ++++ lib/undoable_helper.rb | 23 ++ migrations/001_create_undo_records.rb | 32 +++ spec/rur_spec.rb | 132 ++++++++++++ spec/spec_helper.rb | 26 +++ spec/undo_action_spec.rb | 46 ++++ spec/undo_manager_spec.rb | 10 + spec/undo_record_spec.rb | 368 +++++++++++++++++++++++++++++++++ spec/undoable_spec.rb | 46 ++++ 17 files changed, 1153 insertions(+), 0 deletions(-) create mode 100644 .gitignore create mode 100644 MIT-LICENSE create mode 100644 README create mode 100644 Rakefile create mode 100644 init.rb create mode 100644 lib/undo_action.rb create mode 100644 lib/undo_manager.rb create mode 100644 lib/undo_record.rb create mode 100644 lib/undoable.rb create mode 100644 lib/undoable_helper.rb create mode 100644 migrations/001_create_undo_records.rb create mode 100644 spec/rur_spec.rb create mode 100644 spec/spec_helper.rb create mode 100644 spec/undo_action_spec.rb create mode 100644 spec/undo_manager_spec.rb create mode 100644 spec/undo_record_spec.rb create mode 100644 spec/undoable_spec.rb
And finally, send the changes to svn
$ git-svn dcommit Committing to svn+ssh://svn.nanorails.com/home/psq/svn/plugins/plugins/rur ... A .gitignore A MIT-LICENSE A README A Rakefile A init.rb A lib/undo_action.rb A lib/undo_manager.rb A lib/undo_record.rb A lib/undoable.rb A lib/undoable_helper.rb A migrations/001_create_undo_records.rb A spec/rur_spec.rb A spec/spec_helper.rb A spec/undo_action_spec.rb A spec/undo_manager_spec.rb A spec/undo_record_spec.rb A spec/undoable_spec.rb Committed r66 A Rakefile A .gitignore A init.rb A lib/undo_manager.rb A lib/undo_action.rb A lib/undo_record.rb A lib/undoable_helper.rb A lib/undoable.rb A MIT-LICENSE A spec/undo_record_spec.rb A spec/rur_spec.rb A spec/undoable_spec.rb A spec/spec_helper.rb A spec/undo_manager_spec.rb A spec/undo_action_spec.rb A migrations/001_create_undo_records.rb A README r66 = 98602d45907206a281f597f87445397f069cdc1d (nanorails) No changes between current HEAD and refs/remotes/nanorails Resetting to the latest refs/remotes/nanorails
And then there was much rejoicing across the land :)
Now, to update svn, the only things to do, assuming master is where the latest is, are:
$ git checkout local-svn $ git merge master $ git-svn dcommit
This setup could also bring changes back from svn, which git-svn is capable of doing, but I’ll be quite happy with the read-only part.
Resources:
Update: in fact, it looks like “git-svn dcommit” from the master branch, without merging to the “local-svn” branch first, also commits to svn.