SVN Repositories

=Intro=

Subversion is a free/open-source version control system. That is, Subversion manages files and directories over time. A tree of files is placed into a central repository. Here is how to set it up on your machine.

Please note that this is only a summary tutorial. If you have any questions or need more information or help, feel free to check out the official subversion book which has detailed information on everything, as well as the subversion Frequently Asked Questions page. This is not a guide that will teach you everything about SVN, just how to set it up and use it.

=Installing=

Installing is fairly simple. All you need to do is the following. Below are examples of a few distributions.

Gentoo emerge -a subversion

Centos / Redhat Enterprise yum install subversion

Debian / *ubuntu sudo apt-get install subversion

=Connection=

SVN Repositories can run through many mediums, including SSH, and Apache HTTP/HTTPS. I recommend SSH because it's secure. For more information on why, as well as the other methods, please check Chapter 6 of the SVN Book. This guide will assume we're using SSH.

=How To Connect=

You have a choice between using the command line to do everything, or a user-friendly GUI application. Choose one of the methods below (easier to select one from the content list up top).

GUI clients
The best GUI client I found so far after testing is SmartSVN. It's cross platform (windows, linux, and mac), and easy to use. It's a bit intense when it comes to committing a few thousand files due to it running on java, but that's not a big issue and it's virtual memory usage can be increased.

For windows users, tortoisesvn is really good. However, it's not cross platform.

Alternatives are SyncroSVN (mac) SvnX (mac), SubCommander (mac).

A list of the clients can be found a few sections below.

Command Line
If you need more information on how to use subversion, visit [http://svnbook.red-bean.com/nightly/en/svn.tour.html Chapter 2. Basic Usage] of the original SVN Book. It explains everything in detail.

The three most common arguments you will most likely use are: svn commit (ci) (To update your changes into the repo), svn checkout (co) (to get the latest from the repo), and svn export (to export the final project when you're done, without all the .svn/ related information). You will check them out to work on them with checkout, and you'll commit the changes back into the database with commit. It's pretty simple once you see them in use a few times.

Creating a repository
The steps:
 * Create an SVN repository (then restart apache)
 * Copy any SVN Hooks if needed
 * Create your first revision files and folders
 * Commit that first revision.

Step 1 - Create an SVN repository
Step 1 is to create the repositories.. All repositories will be located in /svn/. If the folder does not exist, simply create it yourself. To add a repository, for example, called xushiproject, change directory to /svn/ and create it with:

cd /svn svnadmin create xushiproject

Step 2- Copy any SVN Hooks needed
Note: This is optional. If you do not want hooks for now, you can ignore this step.

Hooks perform certain automated tasks, such as checking something before one commits, or emailing you after someone commits, with details, and so on.. I recommend using the post-commit script which emails you when someone commits, showing the files and optionally the lines of code that changed. All you have to do is rename the post-commit.tmpl file to post-commit, and make it executable.

cd /svn/xushiproject/hooks/ mv post-commit.tmpl post-commit chmod a+x post-commit

Also, copy this commit-email.pl file to the hooks folder and update the path in post-commit if needed. The commit-email.pl file will show you a list of files that changed. If you would like to see the lines of code as well, then use this commit-email-diff.pl file instead, and update the line in post-commit.pl.

If you want to add more emails to the SVN Send-on-commit list, just edit the /svn/xushiproject/hooks/post-commit file you just copied, and append the email to the line before the last. For example,

/svn/xushproject/commit-email.pl "$REPOS" "$REV" -h hellskitchen.com -s "[$REPOS]" joe@example.com jack@example.com jil@example.com

Step 3 - Create your first repo revision
Your new project has to have 3 folders in it, branches, tags, and trunk. Leave branches and tags empty. Put all your files (the CMS etc...) in trunk/. Say you have a new project called Sa7lab, it should include the following, . |-- xushiproject |  |-- branches (empty) |  |-- tags     (empty) |  `-- trunk |      |-- index.php |      |-- templates/ |      `-- etc......

The quickest way to do that is to create a temp folder: mkdir -p temp/{branches,tags,trunk} cd temp/trunk ... unzip content here

Step 5 - Import your first revision
When done, just import it with svn import /tmp/temp/ file:///svn/xushiproject -m "Initial Create"

That's it.

Checking out
After you obtain your username and password, to checkout a project listed below, just enter the following

In order to start editing, you need to first create a new “working copy” of the data locally on your machine. Ask Subversion to “check out” a working copy of the project.

xushi@localhost ~ cd /tmp xushi@localhost ~/tmp $ svn co svn+ssh://localhost/svn/xushiproject/trunk Password for 'xushi': **** A   indemajtech/trunk A   indemajtech/trunk/images A   indemajtech/trunk/images/image_3-old.jpg A   indemajtech/trunk/images/asdf-email.gif A   indemajtech/trunk/images/logo-old.gif A   indemajtech/trunk/images/logo-old2.gif A   indemajtech/trunk/images/asdf.jpg A   indemajtech/trunk/images/logo.gif A   indemajtech/trunk/images/asdf-asdf.gif A   indemajtech/trunk/md5ck.php A   indemajtech/trunk/index.html Checked out revision 17.

Now you have a personal copy of the repository in a new directory named xushiproject. You can edit the files in your working copy and then commit those changes back into the repository.

Editing and Committing
As you can see, you've checked out revision 17 from the server. Now you can edit some things and commit the changes back to the server.

xushi@localhost ~ cd xushiproject xushi@localhost ~ nano index.php -- Add or delete something and save. xushi@localhost ~ svn commit -m "Added a line to index.php." Sending       index.php Transmitting file data. Committed revision 18.

Adding & Deleting items
How do you add more files to an already existing repo directory? Easy, with the add argument. Go ahead and check out your latest project, copy a file over to the directory, add, then commit the changes.

Check out the latest revision if you haven't already...

Add anything, for example, a test.php file

xushi@localhost ~ cd xushiproject xushi@localhost ~ nano test.php ( create a new file or whatever ) xushi@localhost ~ svn add test.php A        test.php

Commit the new results back to the repo

xushi@localhost~ svn commit -m "Added a new file." Adding        test.php Transmitting file data. Committed revision 19.

To delete items simply use delete instead of add. Commit your changes back up, and you're good to go.

Reverting
Ok, this is all great but how do I revert back to an older revision? If you're not sure as to what revision you're at, then check out the log command. This is why you put a message into every commit. Short and to the point, but enough information to ring a bell that you perhaps forgot about.

xushi@localhost ~ svn log svn+ssh://localhost/svn/xushiproject/trunk

Notice the output xushi@localhost ~/tmp $ svn log svn+ssh://localhost/svn/xushiproject/trunk r17 | xushi | 2007-05-23 11:23:11 +0300 (Wed, 23 May 2007) | 1 line created new project xushitopia... r16 | xushi | 2007-05-23 11:22:25 +0300 (Wed, 23 May 2007) | 1 line Deleted tags

You'll get a nice complete list of revision numbers with the comments, like I mentioned above. This allows you to pick which revision you want to check back out now. xushi@localhost ~ svn co -r 16 svn+ssh://localhost/svn/xushiproject/trunk

This command will drag down revision number 16.

Exporting the result
Finally, when you're all done, and ready, and wish to export a working version to your client, make sure to use the svn export command, to get rid of all the .svn/ related files and folders.

xushi@localhost ~/tmp $ svn export svn+ssh://localhost/svn/xushiproject/trunk A   trunk A   trunk/images A   trunk/images/image_3-old.jpg A   trunk/images/asdf-email.gif A   trunk/images/logo-old.gif A   trunk/images/logo-old2.gif A   trunk/images/asdf.jpg A   trunk/images/logo.gif A   trunk/images/asfd-asdf.gif A   trunk/index.html Exported revision 19.

Just rename the trunk folder to anything else, compress it, and you're ready to go!

GUI Clients
There are many out there. My recommendation is to use [SmartSVN]. However, if you want a full working IDE+SVN+Debugger, you have many choices (Eclipse, Zend Studio, Visual Studio, etc..).

SmartSVN
It's very easy, cross platform, so we'll all use the same, and free.

Download and install it.

Once done, you'll need to add a repository to it. Repository -> Manage Profiles

Click on Add, then Enter SVN URL.... Enter the Repository you need, eg, for project xushiproject, the url will look like svn+ssh://username@localhost/svn/xushiproject It should fill the rest for you. Click next, add the password and tell it to save the password.

Next, you need to checkout the project from the repository. For that, Project -> Checkout

Make sure you've selected the correct repository profile, click Next.

You will now be confronted with the list of Directories. All the data is found in the trunk. Select that directory and click Next, then add it into a directory in your htdocs.

When done, everything else is as indicated.. You have the two update/commit buttons on the top left.

TortoiseSVN
Another SVN application. To me it looked complicated. I don't recommend it unless you know what you're doing.

Zend Studio
First, switch Zend's Source Control Manager from CVS to SVN,

Tools -> Options -> Source Control -> Source Control Tool = Subversion

Make sure the path to SVN there is correct, depending on where your svn binary is.

then Checkout what project you want. Tools -> Subversion -> Checkout

You have a choice between checking out in a local directory of yours, then moving it manually to HTDOCS, editing, then when finishing, moving back, OR just put the project directly to HTDOCS and save yourself the trouble.. it's up to you.

Afterwards, add the result to a new project. Project -> New Project

Eclipse
Will update soon

Visual Studio
No clue yet...