A web application project I’m working on uses YUI widgets for the user interface and CVS as the version control repository. We needed to keep separate versions of YUI around for development, testing and production, so we separate the versions by their release numbers.
Adding a new YUI build tree to CVS means adding several hundred new files to CVS. Unlike Subversion or Git, if you add a directory to an existing CVS project CVS doesn’t automatically add all of the subdirectories and files. If you try to add all of the files in a subdirectory using “*” you will also get the CVS directory that CVS uses to store information about the directory’s contents, which will generate warning messages from CVS until the end of time.
If you combine the “find” command with “cvs add” you can add all of the subdirectories and files with one command, skipping all of the CVS subdirectories. The syntax is a little arcane, so I thought it was worth posting here.
For the initial setup assume that I have an existing CVS project “apache” with a directory “js”. I add the directory ~/apache/js/yui to my local copy of the project, copy the YUI zip file into the directory, and unzip it. Unzipping it creates the directory “yui” (in this case ~/apache/js/yui/yui) but since I want separate versions of each copy of YUI I rename the directory and call it “2.8.0r4”. Then I add the new directories to CVS.
# mkdir ~/apache/js/yui
# cp yui_2.8.0r4.zip ~/apache/js/yui/
# cd ~/apache/js/yui
# unzip yui_2.8.0r4.zip
# mv ~/apache/js/yui/yui ~/apache/js/yui/2.8.0r4
# cd ~/apache/js
# cvs add yui
# cvs add yui/2.8.0r4
I want to add the directory ~/apache/js/yui/2.8.0r4/build to CVS as well, but I don’t want to add the “~/apache/js/yui/2.8.0r4/examples” or “~/apache/js/yui/2.8.0r4/docs” directories, just ~/apache/js/yui/2.8.0r4/build, so I use a “find” command that specifies just the “build” directory and I prune out any directories containing the name “CVS” from the results returned by find:
# cd ~/apache/js/yui/2.8.0r4/
# for f in `find ./build -name CVS -prune -o -print | sort`; do cvs add $f; done
# cvs ci -m "Adding YUI v2.8.0r4 to the CVS repository"
Piping find’s results to the “sort” command puts the files in order, so directories always get added before the files that they contain.
To use this technique for your own directories, just go to the parent of the directory you just added and use the above “find” command, just substitute the name of your new directory for “./build”.
A side note: We add a symlink that points to the version we want to use at the moment so that the application code can be run with whichever version we want to test with:
# cd ~/apache/js/yui
# ln -sf 2.8.0r4 current
A script tag in the application would look like this:
Hope you find this useful.Follow earlruby