CSE 303 cvsExercises

Due: NA

Introduction

These exercises cover only the most commonly used commands, and only the most commonly used switches to those commands. More complete documentation is available all over the web. The definitive guide is at http://www.cvshome.org.

Note: Under cygwin, you may have to re-run setup to install cvs. You will also need ssh (listed as "OpenSSH").

What follows is broken into two sections. The first covers the commands you use day to day: the cvs repository has been built and the initial project files entered into it. The problem now is to do the equivalent of checkout and checkin. The second section covers things you do less fequently: create a new project and create a new repository.

Working with an Existing Repository and Project

Note that, unlike RCS, cvs works on the entire project tree. Also, rather than keeping repository copies of files locally (in directory RCS, they are kept remotely.

These examples use a test repository on attu. Because you will be actually modifying that repository, it's not possible to write down exactly what you'll see. It should be apparent to you what is happening, though.

Fetch a working copy of a project

Unlike the other commands in this section, you do this once, when you first want to establish a working directory for some repository project.

Create a directory for testing and cd into it. Making sure to substitute your own login name for 'yourlogin', enter this:

  cvs -d :ext:yourlogin@attu.cs.washington.edu:/cse/courses/cse303/cvsTestRepository checkout testProj
The parameter to the -d switch is the location of the cvs repository. The ext indicates that it should be accessed using ssh. Following that is the account name to use and the machine name, and following that is the absolute path name of the repository on that machine. (You'll need to provide your attu password, as cvs will be logging in there on your behalf.)
IF that command fails, then export CVS_RSH="ssh" and try it again. You need that environment variable set every session, so you might as well put it in your ~/.bash_profile. (I think the default cygwin install arranges for it to be set, so the command above will most likely just work the first time you try it.)
You've just created a directory, testProj, and a copy of a tree of files taken from the repository has been put into it. You'll notice that directories named CVS are placed in each (other) directory created. They contain information that lets cvs find the repository for all other commands in this section -- you'll never have to type that horrible -d :ext:... parameter again.

Checking files in

All files in your working directory are editable. If you and some other user update the same file and then both try to commit it, cvs will attempt to merge your changes. Most often, this works as you want. See the full manual if you want more information about merging.

Edit the file test.c, then

cvs commit
The editor that comes up is asking for you to attach a comment about what it is you've changed. (If you don't recognize the editor, it's probably vi. Type ':q' to get out of it (without the apostrophes), then just hit enter to the line warning you you didn't leave a comment.)

Now cdinto subdir and edit subdirTest.c. cd .. (back to the root working directory) and repeat the cvs commit command.

Bringing your working directory up to date

Because other users (or you, in another working directory possibly on another machine) will commit files from time to time, you'll want to update the files in your working directory to the latest versions. (Once again, cvs will merge any changes in the repository copy of a file with your working copy if you have modified the local file and the repository copy has changed.)
cvs update
updates all files in the current working directory subtree starting with the current working directory. Importantly,
cvs update -d
does the same thing, but also creates new directories in the working directory subtree if they have been created in the repository. (Leaving off the -d switch you get up to date copies only for files in directories that exist locally already.)

Other commands

cvs add filename Schedules a file to be added to the repository. The file is not actually copied to the repository until you execute a commit, unless the file is a directory (in which case a directory with that name is created in the repository, but the directory contents are not).
cvs remove filename Schedules the "deletion" of a file from the repository. (A) You must first delete the file from the current working directory. (B) The file is not actually deleted -- it's moved to a directory in the repository named Attic. (C) Removal doesn't occur until you do a commit.

Creating a new Project in an Existing Repository

Basically, the idea is to create a set of files in a directory, and then to "import" those into the cvs repository as the project. (You can add additional files later.)

cd into the directory containing the files for the new project.

  cvs -d :ext:yourlogin@attu.cs.washington.edu:/cse/courses/cse303/cvsTestRepository import proj/name vendorname start
The parameter to the -d switch names the repository. import is the command to establish a new project. proj/name is the project name, which can be a path. That path, whatever it is, is created in the repository, starting at the repository's root directory. vendortag is a vendor tag. (I usually just use something like "cse303".) start is a start tag. (We have little use for the vendor or start tags, typically, but they're required.)

Having done that, you should be able to checkout the project from anywhere -- another directory on the same machine, your home machine, your friend's machine, etc.:

  cvs -d :ext:yourlogin@attu.cs.washington.edu:/cse/courses/cse303/cvsTestRepository checkout proj/name

Creating a new Project in an Existing Repository

Login to a machine that is reachable via ssh (like attu), then:
cvs -d <absolute path name of a directory> init
That will initialize the directory you named. As always, the path name must be an absolute path name (one starting at the root dircectory, '/').

init creates a single project, CVSROOT, that contains some administrative files. There is one that's important to you: cvswrappers. It contains a list of file name extensions for files that contain binary data. This is important because when you check in a file, cvs by default will diff it with older versions and save the diff. That doesn't work on binary files, with the result that when you retrieve the file from the repository you find it has been corrupted.

To fix this, checkout the CVSROOT project (just as you would any project). Now edit the cvswrappers file, following the comment and examples you see inside, then commit.