home > cvs > moving a cvs repository and reassigning working copies
This document explains how to move a CVS repository to a new machine or location, and also how to update a working copy to use the repository in its new location. This is necessary because when you check out a working copy, it “remembers” where you got it from.
To move a cvs repository the basic process is to tar it up, transfer it to its new location, then untar preserving permissions.
To tar up the repository, from the cvsrep’s parent directory:
tar -zcf mycvsrep.tar.gz cvsrep/
What the options mean: z means compress (with gzip), c means create a new archive, and f means use the filename specified on the command line.
Then transfer the file then extract with permissions preserved:
tar -zxpf myarchive.tar.gz
What the options mean: z means uncompress (with gzip), x means extract from the archive, p means preserve permissions and again f means use the file specified on the command line.
The easy way to get a working copy that uses the new repository location is simply to check out a new copy from the relocated repository (either by changing your CVSROOT environment variable or by specifiying a repository on the command line via the -d option).
Sometimes you might not want to do this. Perhaps you have customised configuration files set up locally so that a system works on your own machine. Maybe you have folders of test data or images that are needed to make working on the project on your machine easier. Perhaps you want to preserve log files you’ve created during testing. Maybe its a large project and you don’t want to drag it all down from a remote server again.
With a little bit of shell scripting, you can reassign an existing working copy to use a new repository.
Note: this works for me, but please make a copy of your project before running any of these scripts – I can’t guarantee that nothing will go wrong!
First an acknowledgement: the original idea for these scripts came from a page written by Frank Naumann about the FreeMiNT CVS Repository.
Okay, on to the scripts. They are written for the bash shell. If you’re impatient you can just download the scripts and hack away. The download includes a couple of additional scripts that will display the location of the CVS Root and CVS Repository for a working copy without changing anything.
First off we need to change the CVS Root for the working copy. Here’s the script that will do the job:
#!/bin/bash # Test whether we got an argument for the new CVS Root value - exit if not # -z <somestring> is a bash conditional experssion that returns true # if the <somestring> has a zero length if [ -z "$1" ]; then echo " You must supply a new value for CVSRoot usage: $0 <newcvsrootvalue> Examples: To change to an external repository accessed via ssh: ./changerepository.sh :ext:crb@webdevcvs:/Users/Shared/cvsrep To change to a local repository: ./changerepository.sh /Users/Shared/cvsrep " exit fi # if we were passed a new CVS Root value on the command line, assign it to # the newRoot variable newRoot=$1 # walk the current directory (find . ) and if the path matches */CVS/Root, # slap the new CVS Root into the files found find . -path "*/CVS/Root" | while read f; do echo $newRoot > $f done
To run this script and change the root, copy and paste the code into your favourite text editor, save it as changeroot.sh in the root directory of your working copy and chmod it to be executable. You can then run it using
./changeroot.sh [newcvsrootvalue]
Where [newcvsrootvalue] is the name of your new CVS Root, for example:
./changeroot.sh :ext:me@newrepository.net:/usr/local/cvsrep
If its just the host name of your repository that has changed, you’re done. If the path to the repository has changed too, you need to also change the CVS Repository path for the working copy. For example, lets say your original repository was located in /usr/local/cvsrep (the default location for cvs repositories). On the new host machine, you’ve decided that you want it on a different volume, so the new path to the repository is /newvol/dev/cvsrep. Here’s a script that will let you tell your working copy about the new path:
#!/bin/bash # Test whether we got an argument for the new CVS Repository value - exit if not # -z <somestring> is a bash conditional experssion that returns true # if the <somestring> has a zero length if [ -z "$1" ] || [ -z "$2" ]; then echo " You must supply the old and new values for CVS Repository usage: $0 <oldcvsrepositoryvalue> <newcvsrepositoryvalue> Example: ./changerepository.sh /usr/dev/cvsrep /Users/Shared/cvsrep " exit fi # Assign Repository values passed on the command line old_repos=$1 new_repos=$2 # walk the current directory (find . ) and if the path matches */CVS/Repository, # replace the old CVS Repository location with the new. We use % to delimit the # regular expression as we expect the locations to include / slashes. find . -path "*/CVS/Repository" | while read f; do newRepository=`cat $f | sed -e s%$old_repos%$new_repos%` echo $newRepository > $f done
To run this script and change the repository path, copy and paste the code into your favourite text editor, save it as changerepository.sh in the root directory of your working copy and chmod it to be executable. You can then run it using:
./changerepository.sh [oldcvsrepositorypath] [newcvsrepositorypath]
For example:
./changerepository.sh /usr/dev/cvsrep /newvol/dev/cvsrep
You’re done – your existing working copy should now work fine with the new repository.