This should be straightforward, but it’s not. To import (not track, but just import) code from a remote CVS repository to a local git repository, you need to do the following:
- Be certain you have the git-core package installed on your system and that this package includes the
git-cvsimportcommand. You can run
git help -a | grep cvsimportto verify this.
- Be certain you have the
cvspscommand-line tool installed. This does not come with the git suite of tools, so you’ll need to get it separately. If you’re a lazy Mac OS X user, like me, you can use MacPorts:
sudo port install cvsps. Otherwise, get it from the source.
- Prepare your CVS login information for the remote server before you run
git cvsimport. You need to do this so that the git tool will be able to log you in to the CVS server automatically. The command for this looks like:
CVSROOT=:cvs-login-method:email@example.com:/path/to/CVS/root cvs login
For example, if you’re pulling code from the anonymous CVS server that runs on Drupal.org, you might use this:
CVSROOT=:pserver:firstname.lastname@example.org:/cvs/drupal-contrib cvs login. This command will prompt you for the password for the user you specified at the server you specified (for anonymous access, the password is almost always
anonymous) and will hash this in the
~/.cvspassfile for future use by CVS
- Finally, run the
git cvsimporttool, and specify the proper options. Using the Drupal example above, your command might look like this:
git cvsimport -v -d :pserver:email@example.com:/cvs/drupal-contrib contributions/modules/module-name
This would login to
cvs.drupal.orgusing the CVS‘s
pserverlogin method, provide the username
anonymousand the password you specified in the previous step that is hashed in
~/.cvspass, set the CVS document root to
/cvs/drupal-contrib, and pull the code located at
contributions/modules/module-nameinto the current working directory as a git repository.
This works pretty nicely, and creates a git repository just as though you’d created it with
git init in the current working directory.
If you get an error that looks like this:
AuthReply: cvs [pserver aborted]: descramble: unknown scrambling method
then you’ve most likely specified the CVS document root incorrectly. Most notably,
git cvsimport does not understand a CVS document root wherein the password is specified in the document root URL itself. So, for example,
git cvsimport -d :pserver:password:firstname.lastname@example.org:/path/to/CVS/root code/to/checkout will not work. Omitting the password and the separating colon from the URL should fix it.