Subversion

Here I'm going to describe the steps to get subversion up and running. I am using Debian Etch as the preferred OS. Access to the repository will be done via apache (secured with SSL)

Installation

Install the needed packages:

apt-get install apache2 subversion libapache2-svn subversion-tools

Create your subversion repository

mkdir /srv/svn
cd /srv/svn
svnadmin create repos

# change owner to apache
chown -R www-data.www-data svn/

Create a (self signed) certificate for SSL:

mkdir /etc/apache2/ssl

# Generate a private key
cd /etc/apache2/ssl
openssl genrsa -out host.key 1024

# Generate a certificate signing request
openssl req -new -key host.key -out host.csr

# Get the certificate signed
openssl x509 -req -days 730 -in host.csr -out host.crt -signkey host.key

Make sure all needed modules are enabled for apache

a2enmod ssl
a2enmod dav
a2enmod dav_svn

Add port 443 (SSL) to /etc/apache2/ports.conf and remove port 80 (I don't want unsecured access to apache). So ports.conf should look like:

Listen 443

Create your authfile for apache basic auth:

cd /etc/apache2
htpasswd -m .htpasswd svnuser

Create your /etc/apache2/svn-authzfile:

# read access for all
[/]
* = r

# rw access only for svnuser in "repos":
[repos:/]
svnuser = rw

Edit your apache configuration to enalble subversion. First I disable the “default” site:

a2dissite default

Create a new site (e.g. svn): editor /etc/apache2/sites-available/svn

<VirtualHost _default_:443>
        ServerName svn.domain.tld

        SSLEngine on
        SSLCertificateFile /etc/apache2/ssl/host.crt
        SSLCertificateKeyFile /etc/apache2/ssl/host.key

        ServerAdmin webmaster@localhost
        DocumentRoot /srv/svn/

        <Directory /srv/svn/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        <Location /svn>
                DAV svn
                # any "/svn/foo" URL will map to a repository /srv/svn/foo
                SVNParentPath /srv/svn
                # our access control policy
                AuthzSVNAccessFile /etc/apache2/svn-authzfile

                SSLVerifyClient none
                SSLOptions +StdEnvVars

                # try anonymous access first, resort to real
                # authentication if necessary.
                Satisfy Any
                Require valid-user

                # how to authenticate a user
                AuthType Basic
                AuthName "Subversion repository"
                AuthUserFile /etc/apache2/.htpasswd

                <LimitExcept GET PROPFIND OPTIONS REPORT>
                        Require valid-user
                </LimitExcept>
                DavDepthInfinity on
        </Location>

        ErrorLog /var/log/apache2/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /var/log/apache2/access.log combined
        ServerSignature On
</VirtualHost>

Activate the new site:

a2ensite svn

Reload apache

#first check if configs are ok:
apache2ctl configtest

#then reload
/etc/init.d/apache2 force-reload

Ready for action …

Usage

Common tasks you would perform with your fresh subversion install :-)

initial import

Assumption: you have created your initial repository layout and want to import this layout into your repository called “workbench”:

cd ~/tmp
ls
workbench
 
svn import workbench/backup+restore/ https://svn.domain.tld/svn/workbench

revert to a specific revision

Imagine you are at revision 34. You want to revert back to revision 32, where you introduced two changes which didn't work out. This is how to do it:

svn update
svn merge -r 34:32 .
svn commit -m "Rolled back to r32"

amend a log entry

If you have to amend a log entry after you committed, you can do like so on the subversion server:

echo "new commit log entry" > /tmp/commit.txt
svnadmin setlog /srv/vcs/apache --bypass-hooks -r 35 /tmp/commit.txt
svn log -l 4
rm /tmp/commit.txt

svn

Get help:

svn help
svn help command

Update your working copy:

svn up

Revert to an specific revision:

svn up -r 14

Commit a changeset:

svn ci -m "logentry what I did"

Checkout a subdirectory of your repos:

svn co file:///path/to/repos/subdir/ 

See which files were modified in your working copy:

svn stat

Add a file to your repos:

svn add file

Add all files in a directory to your repos:

svn add dir/

Only add a directory (without the files within)

svn add --non-recursive dir/

List all the files in the current working copy which are under version control:

svn list -Rv

Throw away your local changes and revert to the version in the repos:

svn revert filename

Undo/revert a commit

# to revert the changes made in revision 15, assuming your working dir is currently on rev 15
# (svn status will tell you)
svn merge -c -15 .

# you might do additional changes or just commit what was reverted

Keywords

Sometimes it is handy to see (printed in the file) which version of a given file you're using. You can activate some keywords for a specific file:

svn propset svn:keywords "Date URL Revision" .bash_login

Or if you want to set keywords for all files from here:

find . -type f -exec svn propset svn:keywords "Id URL" {} \;

Add the following keywords to your file:

$LastChangedDate$
$Revision$
$URL$

And you will get something like this (after commiting your changes):

#----------------------------------------
# $LastChangedDate: 2007-02-07 13:26:22 +0100 (Mi, 07 Feb 2007) $
# $Revision: 2 $
# $URL: https://svn.domain.tld/svn/repos/.bash_login $
#----------------------------------------

export LS_OPTIONS='--color=auto'
eval `dircolors`
alias ls='ls $LS_OPTIONS'
alias ll='ls $LS_OPTIONS -l'
alias l='ls $LS_OPTIONS -lA'

[...]

Available Keywords:

  • Date
  • Revision
  • Author
  • HeadURL or URL
  • Id

Configuration

You'll want to customize some aspects of your repositories as well as your personal subversion config.

~/.subversion/config

[helpers]
editor-cmd = joe

[miscellany]
log-encoding = latin1
global-ignores = *.o *.lo *.la #*# .*.rej *.rej .*~ *~ .#* .DS_Store
enable-auto-props = yes

[auto-props]
*.conf = svn:keywords="Id URL"

Move subversion repository

I had to move my repository to a new location on an nfs volume. What I did:

  1. dump the repos to file
  2. create repos in the new place
  3. run rpc.lockd on all client machines to enable locking (only reasonalbe with FSFS as the backend)
  4. load dump
  5. relocate client working copies to the new location of the repos

In detail:

svnadmin dump oldrepos > oldrepos.dump
svnadmin create newrepos
# if on an nfs-volume, install nfs-utils, then:
/etc/init.d/nfslock start
svnadmin load newrepos < oldrepos.dump
# in existing working copy run
svn switch --relocate file:///path/to/oldrepos file:///path/to/newrepos
vcs/subversion.txt · Last modified: 2013-12 by tb
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0 ipv6 ready