HOWTO+-+Setup+an+SVN+Repository+and+Work+with+it

toc

=Installing Subversion and Apache SVN library=

Use apt-get to install the needed software code sudo apt-get update sudo apt-get install subversion libapache2-svn openssh-server code

=Creating the repository=

Let's say you want your repository to be in, type in these commands: code sudo mkdir -p /var/svn sudo svnadmin create /var/svn/repos --fs-type fsfs code In order to control who has access to the repository we will now add a user who will own the repository files. Adding a user also adds a group with the same name. Use the following command to add the user. Just press enter in every question and set the password for the user when asked for it. (Don`t care so much for the password as we will disable this user for login) code sudo adduser svn code Now make it impossible for anyone to log in as this user by editing to set the 🇸🇮 user shell to. Do this using the command. Find the line which starts with 🇸🇮 (it should be the last line in the file) and change to.

Now change the ownership of the repository files. code sudo chown -R svn.svn /var/svn code

=Adding Projects to the Repository=

A quick way to accomplish this task is to use the command. By first creating the layout in a temporary location on your drive, you can import the whole layout tree into the repository in a single commit: code $ mkdir ~/tmpdir $ cd ~/tmpdir $ mkdir -p projectA/trunk $ mkdir -p projectA/branches $ mkdir -p projectA/tags $ echo " Hello World  " > projectA/trunk/index.html code

Since you have created the layout, run the following command to import you project into the repository we have created above. code svn import. file:///var/svn/repos --message 'Initial repository layout and source addition' code

If the above command ran succesfully, an output like the following one will be shown. code Adding        projectA Adding        projectA/trunk Adding        projectA/trunk/index.html Adding        projectA/branches Adding        projectA/tags … Committed revision 1. code

Now you don`t need the tmpdir anymore so you can safely remove it. code $ cd ~ $ rm -rf ~/tmpdir code

=Setting up Apache for HTTP Access with WebDAV Protocol=

Subversion also supports the WebDAV protocol, to set this up Apache is needed. I am assuming that you installed Ubuntu as a LAMP server (or you have apache installed in any way).

You must add the following snippet in your file: NOTE: is actually a symbolic link of code sudo vi /etc/apache2/mods-enabled/dav_svn.conf code

In the directive add: code  DAV svn SVNPath /var/svn/repos AuthType Basic AuthName "Subversion Repository" AuthUserFile /etc/subversion/passwd  Require valid-user   code NOTE: To limit any connection to the SVN-Server (private SVN), remove the lines and.

Next, you must create /etc/subversion/passwd file (that we setup into the above apache directive). This file contains user authentication details.

If you have just installed SVN, the passwd file will not yet exist and needs to be created using the "-c" switch. Adding any users after that should be done without the "-c" switch to avoid overwriting the passwd file.

To add the first entry, ie.. to add the first user, you can run the following command: code sudo htpasswd -c /etc/subversion/passwd vangelis code It prompts you to enter the password. Once you enter the password, the user is added.

To add more users after that, you can run the following command (note that there is no -c as previously): code sudo htpasswd /etc/subversion/passwd mixalis code

Restart Apache: code sudo /etc/init.d/apache2 restart code

Now, to access the repository you can run the following command: code svn co http://machinenameOrIP/svn/projectA --username vangelis code WARNING: The password is transmitted as plain text. If you are worried about password snooping, you are advised to use SSL encryption. For details, please refer next section.

Access via WebDAV protocol with SSL encryption (https)
Accessing SVN repository via WebDAV protocol with SSL encryption (https://) is similar to http:// except you must install and configure the digital certificate in your Apache 2 web server.

You can install a digital certificate issued by Signing authority like Verisign. Alternatively, you can install your own self signed certificate.

This step assumes you have installed and configured digital certificate in your Apache 2 web server. Now to access SVN repository please refer the above section. You must use https: //to access the SVN repository.//

= Access via Custom Protocol (svn) = Edit the following file to configure the access control. code sudo vi /var/svn/repos/conf/svnserve.conf code And uncomment the following lines: code code After uncommenting the above lines, you can maintain the user list in file. The file has examples by default. The syntax of that file is as follows though: code username = password code
 * 1) [general]
 * 2) password-db = passwd

Now, to access SVN via svn: custom protocol either from the same machine or different machine, you have to run as daemon using  command.

Once you run this command, SVN starts listening on default port (3690). To access the project repository, you must run the following command: code svn co svn://machinenameOrIP/var/svn/repos/projectA --username vangelis

code To have this service start automatically on boot, check this sample startup script file.

If you have ssh access on the remote machine, you can use svn+ssh to encrypt the communication. A sample command follows: code svn co svn+ssh://username@machinenameOrIP/var/svn/repos/projectA --username vangelis code NOTE: The ssh username is different than the svn username (vangelis in the above example)

=Setup TRAC=

Install the needed packages from the repositories: code sudo apt-get install trac python-setuptools libapache2-mod-python enscript code

Create a trac database: code sudo mkdir /var/www/trac sudo trac-admin /var/www/trac/repos initenv code Then answer its questions, take the defaults, our Subversion repository is in.

Now to get Apache to run Trac. code sudo chown -R www-data.svn /var/www/trac code

You will also need to create a file named under the folder  with the following content: (to use the authentication read the "Setting up Apache for HTTP Access with WebDAV Protocol" section of this wiki page) code  AuthType Basic  AuthName "Subversion Repository"  AuthUserFile /etc/subversion/passwd  Require valid-user 

 SetHandler mod_python PythonInterpreter main_interpreter PythonHandler trac.web.modpython_frontend PythonOption TracEnvParentDir /var/www/trac PythonOption TracUriRoot /trac  code

and make a symbolic link to the code ln -s /etc/apache2/sites-available/trac /etc/apache2/sites-enabled/trac code

Restart Apache: code sudo /etc/init.d/apache2 restart code

=Using SVN From the Client Machine=

Since we setup the server we need the clients to be able to use it. The 5 simplest commands you`ll need are the following: For a complete reference, read the [|SVN Book] code svn co <- check out a remote repository to a local one svn update <- update the local repository to the latest revision (or a specified one) svn status <- check the status of the local repository svn add <- add files to be uploaded to the remote repository svn ci <- Commit the added files to the remote repository code

Example of svn co
code mkdir ~/MyProject cd ~/MyProject svn co svn://remotehostIP/var/svn/repos/projectA code

Example of svn update
To the latest version: code cd ~/MyProject svn update code

To a specified revision (128 at the following example) code cd ~/MyProject svn update -r 128 code

Example of svn status
code svn status code

Example of svn add
code cd ~/MyProject touch trunk/test svn add trunk/test code

Example of svn ci
code cd ~/MyProject svn ci -m "Give a description of the commit inside the quotes" --username vangelis code