[Navigation Bar]  
 
 

    

[OpenSUSE powered]
[BUSH powered]
[vi powered]
[XML] [RSS]

 How to manage your sources and how to work remotely with CVS.

Source control programs manage changes to a software project and allow multiple programmers to work together without destroying each other's work. Even for a single programmer, source control will allow you to create branches of the same project for different clients, or to rollback changes to an older version of the project. The most popular source control programs for Linux are CVS and subversion. This page discusses how to get started with CVS.

Many Linux IDE's have built-in support for CVS and subversion but they usually expect you to be familiar with source control concepts.

 CVS Concepts

CVS stores the project in a directory called the repository. This is a kind of database that records all the files and changes in the project.

There are three basic CVS activities:

  • Check Out - get a copy of a project
  • Update - automatically patch your copy with any changes made by other developers
  • Commit - submit your changes to the other developers. The project must be updated before it can be committed.

CVS documentation is located at http://ximbiot.com/cvs/manual/cvs-1.11.21/cvs.html#SEC_Top.

 Setting up CVS

On the computer with the respository, start a shell session and declare a CVSROOT variable that contains the name of the directory for the repository. /home/repository/cvs might be a good name. The /home directory is often on a separate partition to protect it from Linux distribution upgrades. It's also good practice to back up /home on a regular basis and this will save your projects at the same time.

export CVSROOT="/home/repository/cvs"

To initialize CVS, use the CVS initialization command:

cvs init

To add a project to CVS, import it. Move to the top-most directory of the project and use CVS import. Give the project a name (it can contain directories) and identifiers for yourself and the release. "init-rel" for initial release might be a good choice. Suppose that you are doing a web site for a company named "Snorkel Inc.".

cvs import web/snorkel_inc user init-rel

To work on the project, rename the old directory to a backup directory (to avoid overwriting in case of a problem). Move to where you want the project to be saved and check out the project:

cvs co web/snorkel_inc

 Working on a CVS Controlled Project

To update your project with the latest changes by your fellow programmers, move to the directory to update and type:

cvs update

You can also update individual files (instead of the directory) by naming files in the command. If new subdirectories were added to the project, use the -d option to create those as well.

To commit your changes to the project so they can be seen by your fellow programmers, move to the directory to commit and type:

cvs commit

You can also commit individual files (instead of the whole directory) by naming files in the command. To avoid typing in descriptions, you can include a description of the changes using -m "message" where message is the description to put in the CVS change logs.

 Using CVS Remotely

To use CVS remotely, you'll want to use a secure shell connection (SSH). Create a secure shell connection and setup your SSH authentication keys so you won't have to type a password. If you've never used SSH, you'll need to generate a pair of SSH keys (e.g. ssh-keygen -t rsa), copy the public key (.ssh/id_rsa.pub) to the remote home directory (or add it) (.ssh/authorized_keys) and make sure the remote key file is not world readable (otherwise it is an automatic rejection by SSH).

In your shell startup file (e.g. /etc/profile, ~/.bash_profile or ~/.bashrc), declare a SSH_RSH variable to indicate how CVS will connect, and a CVSROOT variable to indicate the user login, computer name and where the CVS repository is located.

export CVS_RSH=ssh
export CVSROOT=":ext:user@computer:/home/repository/cvs"

If you have to go through a firewall, make sure that the secure shell (port 22) is allowed through to the computer with the repository.

 Using CVS Remotely with Multiple Projects

Create shell scripts to setup the CVS variables for each project. Use the following as an example, replacing the CVSROOT information for your situation.

#!/bin/bash
export CVS_RSH=ssh
export CVSROOT=":ext:user@computer:/home/repository/cvs"
cvs $@

Run the script instead of the cvs command. If you are using an IDE, configure the IDE to use the script instead of CVS directly.

 Using CVS Remotely on a Different Port

Sometimes you may want CVS to work through a different network port than the SSH default. For example, you might be port forwarded through a firewall to a particular machine. Alternatively, port 22 might be used to SSH to a firewall and another port will need to be used to SSH to an internal machine. Use the following script as a workaround. Replace the CVSROOT information for your situation.

#!/bin/bash
export TMP_SCRIPT="/tmp/cvsssh.$$"
echo "#!$SHELL"    $TMP_SCRIPT""
echo "ssh -p 8001 "'$@'    "$TMP_SCRIPT"
chmod 755 "$TMP_SCRIPT"
export CVS_RSH="$TMP_SCRIPT"
export CVSROOT=":ext:user@computer:/home/repository/cvs"
cvs $@
rm "$TMP_SCRIPT"

Run the script instead of the cvs command. If you are using an IDE, configure the IDE to use the script instead of CVS directly.

 Using CVS to Rollout Projects

You can sometimes use CVS to rollout projects, especially web sites. On the production machine, move to the root web directory and use CVS to update the web site (or check out the web site if this is the first time). This will create CVS/ directories (as if the web site was a developer) but it will also update the files on the entire web site. Check file ownerships and permissions as needed.

Documents or web pages can have RCS dollar tags embedded in them. When CVS updates a project, it searches files for dollar tags and replaces them with information about the project. You can use dollar tags in web pages to automatically report when pages were updated and who last changed them. This can be useful for research papers, reports or other material that can become outdated.

This is a basic tutorial. Read the CVS documentation for more features.

Read More:  Managing Projects with Subversion --> 

Read More:  Return to the Front Page --> 

 
     

« Truth Humility Communication Nobility Freedom Purity Excellence Right Support Courage Compassion Quality Honesty Trust Cooperation Challenge Education »
PegaSoft Canada - A Linux Association Since 1994