Showing posts with label SVN. Show all posts
Showing posts with label SVN. Show all posts

Thursday, December 03, 2009

Locking SVN Branches

There are two methods that can be used:

  1. Access control lists
  2. Pre-commit hooks

Access control lists can be used to take away write permission for users. SVN uses two files to configure access: authz and passwd (both located in the conf directory of your repository). Passwd defines users + their passwords and groups of users. Authz defines permissions on repos and their contents for the users and groups defined in passwd. Here is a sample.

Pre-commit hooks can be applied to a path and will reject any write actions. Here is documentation on how to create hooks. Here is python code for a hook and here is a sample configuration for said hook. Basically you put an executable file into svn's repos/hooks folder and give it the name of a hook (the names are based on the operation being performed). Command line parameters are given to the executable by SVN and the executable can perform validation, etc. SVN comes with sample hooks that have a .tmpl filename extension. You can remove this extension to enable the default hook.

SVN Conventions

The conventional layout for a new SVN repo is to contain three directories: trunk, branches, and tags. There are standard ways to use each of these folders. Gavin Baumanis described this fairly succinctly here:

The trunk / branches / tags folders are a naming convention to assist
humans in managing their code.

...

The convention says;
Do all your work in a directory named "trunk".
Do anything that might
break the trunk in a branch (a sub-directory of
the "branches" directory) -
so as not to break the trunk with
experimental code.
Use the "tags"
directory for a snapshot in time of the trunk at a
particular revision -
(File releases / some other milestone you want
to track).

Installing SVN Serve on Ubuntu

Note: if you get an error about the subversion package not being available, change the Ubuntu package repository
[Change Package Repository]
Open System -> Administration -> Synaptic Package Manager -> Settings -> Repositories
Select from the drop down Main server
Click OK
Press the Reload Button and wait for the packages to download
close the Synaptic Package Manager

[Create an svn user]
vi /etc/group
add
svn:x:1000:
or use an available number if 1000 is used

vi /etc/passwd
add
svn:x:1000:GROUP_ID:svn,,,:/home/svn:/bin/bash
replace 1000 with an available user id if 1000 is used

[Install Subversion]
sudo apt-get install subversion
Answer Y to the prompts

[Create Repository Root]
sudo mkdir /var/svn

[Assign SVN ownership to SVN user]
sudo chown -R svn:svn /var/svn

[Start SVN Server]
svnserve -d -r /var/svn

[Create Repository]
svnadmin create /var/svn/YOUR_REPO_NAME

[Modify SVN Server Config]
vi /var/svn/YOUR_REPO_NAME/conf/svnserve.confuncomment the line specifying that username/passwords are stored in a file named passwduncomment the line containing anon-access and set it to none

[Edit list of users]
vi /var/svn/YOUR_REPOSITORY_NAME/conf/passwd
After the line that says [users] you can add users by adding lines in the format
username = password

(optional)[Make SVN start at boot]
[Make SVN start at boot]

Create start script
sudo vi /etc/init.d/svnserve

Paste the following:
svnserve -d -r /var/svn/YOUR_REPOSITORY_NAME
OR
#! /bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/svnserve
NAME=svnserve
DESC="SVN Repository Server Daemon"
test -x $DAEMON || exit 0
# Set your repository root here!
OPTIONS="-d -r /var/svn"
# Get lsb functions
#. /lib/lsb/init-functions
. /etc/default/rcS
start() {
echo "Starting $DESC... "
# echo "Starting $DESC: "
if ! start-stop-daemon --chuid svn --start --quiet --oknodo --exec $DAEMON -- $OPTIONS
>/dev/null 2>&1; then
status=$?
echo $status
return $status
fi
log_end_msg 0
return 0
}
case "$1" in
start)
start
;;
stop)
echo "Stopping $DESC: "
start-stop-daemon --stop --quiet --oknodo --exec $DAEMON
echo $?
;;
restart|force-reload)
$0 stop
sleep 1
start
#echo "$NAME."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0


Make the script executable:
sudo chmod +x /etc/init.d/svnserve

Add the script to the boot sequence:
sudo update-rc.d svnserve defaults

Key thing in the script is to make sure the svn serve user and group is correct or when svnserve runs it will not have permission to modify the repository

(optional) [Perform Initial Import]
sudo svn import /PATH/TO/FOLDER/TO/IMPORT file:///var/svn/YOUR_REPO_NAME -m "Initial Import"

(random) [Restart SVN Server]
sudo pkill -9 svnserve
sudo restart svnserve

You can access the SVN repository at
[Connect To Repository]
URL: svn://YOUR_HOSTNAME_OR_IP/YOUR_REPO_NAME

See http://svnbook.red-bean.com/en/1.1/ch05s02.html for more svnadmin create options

[User permissions]
Edit Users -> must be specified in svnserve.confvi /var/svn/YOUR_REPO_NAME/conf/passwd
Edit permissions -> must be enabled in svnserve.conf
vi /var/svn/YOUR_REPO_NAME/conf/authz

Labels

Blog Archive

Contributors