CVSing back your drupal site.

The benefits of using source control are great. It is like working with another developer, to review your code changes, even if you are all by yourself, not to mention being able to rollback any changes that you have made.

When using drupal, I like to grab core, modules and themes using cvs rather than downloading files. I find it easier to keep core and modules up-to-date while maintaining the patches I might have applied to a module.

The main idea is to download from cvs the same version of your existing site, then copy all the CVS folders in each subdirectory to the appropriate subdirectories of your existing site. Then to run compare with cvs any differences that you have made, and once satisfied, update using cvs to the latest version.

Anybody familiar with drush will know just how useful that tool is. By default drush will grab your files using wget. To use cvs instead to download the drupal project, modules, uncomment this line in drushrc.php


$options['package-handler'] = 'cvs';

However, if you are called in to work with an existing drupal site, that was downloaded not using cvs, and need to upgrade the site, and would like to use cvs to upgrade it, then here is how.

1) Download drupal using cvs:
drush dl

2) Check the version of drupal downloaded, or change it to match the existing site:
cvs up -Pd -r DRUPAL-6-10

3) Edit the shell script below changing fromdir and todir to the appropriate directories. "fromdir" is the folder that was created by step 1, and "todir" is the existing drupal site.


#!/bin/sh
fromdir='/my/source/controlled/site'
todir='/my/destination/site'

cd $fromdir
find . -name CVS -print | \
while read i
do
echo $i
subdir=`dirname $i`
cp -pr $i $todir/$subdir
done

4) Now you can use cvs to see how your existing codebase differs from the drupal version, e.g. directories or files that you might have added. Note that drupal's packaging system adds some lines to all .info files.


cvs up -Pd
cvs diff -up | more

5) If there are some files such as the .info files with irrelevant changes, then delete them, and run update

rm aggregator/aggregator.info
cvs up -Pd

or a more aggressive removal, use with caution

find . -name '*info' -exec rm {} \;

6) Voila, you are done, updating the code is one easy step

cvs up -Pd -r DRUPAL-6-15

Don't forget to update the database


drush up

image from http://dealarchitect.typepad.com/deal_architect/2009/05/rollback-or-cond...