git-svn-dcommit Workaround for Git Submodules
Introduction
This article is a follow-up to my previous article on using git as a front-end for Subversion. That article focused on the issue of git-svn not being able to dcommit upstream to a Subversion repository when sub-modules are present.When an attempt is made to git-svn dcommit a repository which contains submodules (even if the submodules path is in .gitignore) the following error occurs:
Committing to file:///home/sysadm/devbox/testrepo/superproj …
A .gitmodules
A plugintest/myplugin
fatal: git-cat-file 99e6127cfff6447645f01a50dc836081456d0753: bad file
32768 at /usr/bin/git-svn line 450
Why is this a problem for me?
I use Subversion to manage my Rails applications. I have a second Subversion repository that contains all plugins referenced by my Rails applications. Each of my Rails’ vendor/plugin folder contains an svn:externals referencing all my plugins from this second Subversion plugins repository.
This allows me to consistently manage my plugins and ensures that I am running the same version across all my applications.
In an ideal world, I would migrate all my Rails apps to individual GIT repositories and use Git’s submodules to manage my plugins within each Rails application. This, however, is not an option as several reasons (ie clients, deployment and project management tools) require that all code is managed by Subversion.
A solution using GIT sub-projects
My previous article lists possible solutions and problems with each solution. The most promising of these was using Git Subprojects to clone plugins in vendor/plugin. The main Rails’ Git repository is then able to ignore plugins and we are able to dcommit up to svn. WIN
Unfortunately, there is no git-submodule equivalent for managing subprojects. FAIL
Then came along Mike Dalessio and posted a link to gitrake. Mike had done a fantastic job of abstracting plugin management through the use of a few Rake commands. This would have been an ideal solution for me if I was still using Subversion.
I decided to follow Mike's example and write porcelain to manage Git's subprojects in the context of Rails plugins. Git-rails-plugins was born.
git-rails-plugins
git-rails-plugins is a Ruby script that enables a developer to easily clone plugins from either a Git or Subversion repository. When using the latter option, git-rails-plugins first interrogates the svn:externals property of vendor/plugins then clones all referenced plugins.
Git-rails-plugins maintains a .plugins file which lists all plugins. The .plugins file should be tracked in the superproject Git repository to track plugin version.
Usage
Add vendor/plugin to .gitignore.
git-rails-plugins must always be run from RAILS_ROOT.
Add .plugin file (once generated) to your Rails Git repository.
Add a plugin from a Git repository:
git-rails-plugins.rb -a /home/plugins/active_merchantgit-rails-plugins accepts comma separated git paths for adding multiple plugins.
Clone all plugins Using Subversion’s svn:externals
git-rails-plugins -s svn://svn_repos/myapp/trunk/vendor/pluginsThe above command will interrogate the given path's svn:externals and will clone all found plugins locally.
List All Plugins
git-rails-plugins -l
Update Plugins
To update all plugins:git-rails-plugins -uor if specific plugins are to be updated:
git-rails-plugins -u active_merchant,will_paginate,plugin3,plugin4
Push Plugins
To push all plugins:git-rails-plugins -por specific plugins can be listed:
git-rails-plugins -p active_merchant,will_paginate,plugin3,plugin4
Execute Commands
To execute “git checkout master” against all plugins:git-rails-plugins -e :"git checkout master"or against specific plugins
git-rails-plugins -e active_merchant,will_paginate :"git checkout master"
Gimme, gimme, gimme!
git-rails-plugins is currently hosted on GitHub. Please feel free download or fork as you see fit.Nazar started programming on a Zx Spectrum in 1983, when the majority of games were supplied by magazines as source code and had to be keyed in by hand. Nazar started developing professionally in 1995, starting with Oracle Forms 3 and progressing to Delphi in 1998. He founded Panther Software Publishing in 2001 and has since developed and supplied numerous bespoke solutions to various sectors of industry, ranging from: Insurance, Banking, Facilities Management, Health Care, Engineering, Document Control and Procurement.
Panther Software has been specialising in developing bespoke database driven web applications using Ruby on Rails and AJAX since 2006. Contact us for your web application requirements.
Comments closed for this article
What others have said:
|
|
||
|---|---|---|
|
By: Andrew
|
Hmm, it sure takes a while to get plugins from official sources, esp rails ones, as they have tons of history. I wonder if you can limit the amount of history git-svn takes.. |
|
|
Posted about 1 year ago
|
||
|
|
||
|
|
||
|---|---|---|
|
By: nazar
Joined: September 21, 2007
Posts: 18
|
Yes you can Andrew. you can specify either a revision or range of revisions using: git-svn -r 123:321 The above will fetch all SVN revisions 123 upto 321. |
|
|
Posted about 1 year ago
|
||
|
|
||









