How to rename/move files in CVS (infrastructure team)

Last modified: February 5, 2009 - 04:09

Option 1: CVS Add/Remove

mv example.file example2.file
cvs remove example.file
cvs add example2.file
# Make sure to include both file names here so to preserve history.
# If moving between directories, specify the full path.
cvs commit -m "Renaming example.file to example2.file"

Pros: You don't need shell access to cvs.drupal.org to do this.
Cons: History of file gets split between example.file and example2.file. cvs annotate will be confused and think that everything on the newly renamed file started with the initial commit where the file was added.

Option 2: Destructive Rename

This method is useful only if you are renaming a file that no other file references AT ALL, in ANY WAY. For example, a documentation file.

ssh username@cvs.drupal.org
cd /cvs/drupal/drupal/modules/field
mv api.field.php,v field.api.php,v

Pros: All history is retained, looks like nothing ever happened and the file was always named correctly.
Cons: No record will be retained of the old file's name/existence. You also need cvs.drupal.org shell access to do this. Additionally, anyone with a CVS checkout from before this operation with local modifications to the file will receive conflict errors.

Option 3: History-Preserving Rename

The final way is if you are doing major restructuring on files that have been around a long time, are referenced by lots of other files, and you really don't want to split the history between the old and new versions. For example, when core moved all modules/example.module to modules/example/example.module.

Doing this requires some fancy CVS trickery:

a) cp (not mv) the ,v files to retain all blame/history in the new location
b) delete the file from the old location
c) remove all CVS tags and branches from the file in the new location
d) "add" the file in the new location

Since this is an incredible amount of things to remember, there is a nice script in contributions/tricks/cvs_rename/ to do this for you. It's best to run this script from another which sets the proper variables and so on. See http://drupal.org/files/issues/254655_og_move.25.txt for an example. Make doubly sure to TAR UP THE ENTIRE CVS REPOSITORY before you do this.

Pros: Retain full history of files in *both* the new and old file locations.
Cons: Needs shell access to cvs.drupal.org.

Tips

Perform an rsync of the CVS repositories to your local machine and practice there first. If all goes well, upload the resulting dirs to the live repo. This also avoids xcvs validation freaking out and requiring superuser access.

 
 

Drupal is a registered trademark of Dries Buytaert.