User login

Use Git to commit to CVS, such as for maintaining a Drupal module

UPDATE: See http://more.zites.net/git_drupal_contrib_cvs

Kathleen says this is complicated and not necessary - http://drupal.org/node/288873

HOWEVER-- if you ever want to let other people contribute to your project the normal way (if CVS can be considered in any way normal), then you will want the synch anyway.

So, following and building on the instructions Maintaining a Drupal module using Git

$ git version
git version 1.6.0.4

$ sudo apt-get install cvsps
will get cvs if not already installed as well as cvsps.
$ sudo apt-get install git-cvs
will itself get git if you don't have it yet :-)

Indeed, sudo apt-get install git cvs git-cvs cvsps will get everything you need at once on the Debian or Ubuntu command line.

Now, if you do not yet have a CVS repository for your project (or, technically, folder in the giant Drupal contrib repository) you must first create your project in CVS.

Following http://drupal.org/handbook/cvs/quickstart#start

cd ~/code
mkdir cvs
cd cvs
export CVSROOT=:pserver:agaric@cvs.drupal.org:/cvs/drupal-contrib
cvs login
cvs checkout -l contributions/modules
cd contributions/modules

Copy your module in or write it right there. In Agaric's case this time we put in the base, starter files for a module called 'pwn'.

cvs add pwn
cvs add pwn/*
cvs add pwn/tests/*
cvs commit -m "Initial commit of pwn (permit own permissions) module.  Currently just stub files generated by chopping out anything from VotingAPI that we wouldn't want, which was pretty much everything.  This module will allow administrators to grant users the ability to administer any permision that said users have."

In Agaric's case this other time, for the visitorpath module we copied a completed module from the web site project:
cp -pr /home/ben/code/ventus/drupal/sites/default/modules/visitorpath visitorpath

All that is done from the contributions/modules directory, outside of your module directory (in our case, pwn).

We do the next step on our server, because we want everyone on our team to be able to use a central git repository.

(Note: Make sure git, git-cvs, cvs, cvsps are installed on the server you choose, too.)

In our workflow and repository location conventions, doing this the first time, for the pwn module, meant:

mkdir /srv/git/modules
cd /srv/git/modules/
export CVSROOT=:pserver:agaric@cvs.drupal.org:/cvs/drupal-contrib
cvs login
git cvsimport -a -p x -v -C pwn contributions/modules/pwn

Note: Running "git cvsimport -a -p x -v -d :pserver:agaric@cvs.drupal.org:/cvs/drupal-contrib contributions/modules/pwn" directly didn't work so well. In fact, the first authreply was "I HATE YOU." Even after that, it needed the root and login and such. Also note that we use "-C modulename" to create the module directory, in this case pwn. You need to either make the directory in advance and call cvsimport from it (seems to be the approach in the original docs on Drupal.org), or do like we do here.

Back in your local development environment

We cover making the directory which you shouldn't have to do more than once.

cd ~/code
mkdir modules
cd modules
git clone -l git.agariclabs.com:/srv/git/modules/pwn pwn
cd pwn

Every subsequent time, or rather, as you make changes to this project:

git add newfile
git add changedfile
git commit -m "A new file and a changed file to make perfection more perfect."
git push

Still on your local machine.

Yes, this is annoyingly complicated. What do you expect when you combine CVS and git?

First time only... well, might as well do it for each branch:

cd ~/code
mkdir cvswc
cvs -z6 -d:pserver:agaric@cvs.drupal.org:/cvs/drupal-contrib checkout -r HEAD -d pwn contributions/modules/pwn

cd ~/code/modules/pwn
git cvsexportcommit -v -w ~/code/cvswc/pwn bf933043a4467041ee5ededd3853569733bb51f7

Be sure to try the first commit after you start making changes to the project-- for instance, not the first commit.

cd ~/code/cvswc/pwn
cvs commit -F .msg 'pwn.module'

Automated Script

Once the above setup is done, this script will, amazingly, astoundingly, and completely beyond my belief (since I wrote it) actually keep your CVS repository updated from the date you give it up to the most recent git commit.

#!/bin/bash

proj=$1
date=$2

while read line
do
  cd ~/code/modules/$proj
  git cvsexportcommit -v -w ~/code/cvswc/$proj $line
  cd ~/code/cvswc/$proj
  cvs commit -F .msg
done < <(git log --after="$date" --reverse --pretty=format:%H;echo '')

Run it with a command like this:

~/scripts/gitcvs.sh pwn "Wed Jul 22 12:04:11 2009 -0400"

Where pwn is the module name and the date, in quotation marks, is of the kind that can be retrieved from the git log command.