I and my small team work in Git, and the larger group uses Subversion. I’d like to schedule a cron job to publish our repositories current HEADs every hour into a certain directory in the SVN repo.
I thought I had this figured out, but the recipe I wrote down previously doesn’t seem to be working now:
git clone ssh://me@gitserver/git-repo/Projects/ProjX px2
cd px2
svn mkdir --parents http://me@svnserver/svn/repo/play/me/fromgit/ProjX
git svn init -s http://me@svnserver/svn/repo/play/me/fromgit/ProjX
git svn fetch
git rebase trunk master
git svn dcommit
Here’s what happens when I attempt:
% git clone ssh://me@gitserver/git-repo/Projects/ProjX px2
Cloning into 'ProjX'...
...
% cd px2
% svn mkdir --parents http://me@svnserver/svn/repo/play/me/fromgit/ProjX
Committed revision 123.
% git svn init -s http://me@svnserver/svn/repo/play/me/fromgit/ProjX
Using higher level of URL: http://me@svnserver/svn/repo/play/me/fromgit/ProjX => http://me@svnserver/svn/repo
% git svn fetch
W: Ignoring error from SVN, path probably does not exist: (160013): Filesystem has no item: File not found: revision 100, path '/play/me/fromgit/ProjX'
W: Do not be alarmed at the above message git-svn is just searching aggressively for old history.
This may take a while on large repositories
% git rebase trunk master
fatal: Needed a single revision
invalid upstream trunk
I could have sworn this worked previously, anyone have any suggestions? Thanks.
There are a few issues with your approach:
git svn init. Rebasing assumes a common ancestor, but if your git repo was previously initialised viagit init, thengit svn initwill create a second root (i.e. parent-less) commit, and rebasing from one tip to the other will not work without--onto.-soption togit svn init, which causes it to search forbranches/,tags/, andtrunk/. As the warning (Using higher level...) clearly states, this results in thegit-svnconfig pointing at the top of the svn repo, not thefromgit/ProjXsubdirectory.trunkeven though there’s no good reason for this branch to exist;git svn initactually creates a tracking branch calledremotes/git-svn.So the actual sequence you want is:
Now hacking can occur concurrently in git and svn. Next time you want to
dcommitfrom git to svn, you simply do:If you already initialised the git repository, started hacking in it, and need to transplant that history into svn, then the first-time-only sequence is more difficult because you need to transplant all the git history into svn, even though they don’t share a common ancestor:
Subsequently, do the same
svn rebaseanddcommitas before.In case anyone wants to test this approach in a sandbox, you can download my test script. I’d recommend you do a visual security audit before running though 😉