Loading

Subversion

This wiki document explains how to setup Subversion alias SVN on Ubuntu. The intended audience is experienced Linux users and system administrators.

Introduction

If you are new to Subversion, this section provides a quick introduction.

Subversion is an open source version control system. Using Subversion, you can record the history of source files and documents. It manages files and directories over time. A tree of files is placed into a central repository. The repository is much like an ordinary file server, except that it remembersevery change ever made to files and directories.

Assumptions

It is assumed that you are aware of how to run Linux commands, edit files, start/stop services in an Ubuntu system. It is also assumed that Ubuntu is running, you have sudo access and you want to use Subversion software.

It is also assumed you have an internet connection.

Scope of this document

To make an SVN repository available to access using the HTTP protocol, you must install & configure web server. Apache 2 is proven to work with SVN. The installation of Apache 2 Webserver is beyond the scope of this document. (SeeApacheHTTPserver.) However, the configuration of Apache 2 Webserver for SVN is covered in this document.

To access an SVN repository using HTTPS protocol, you must install & configure digital certificate in your Apache 2 web server.The installation and configuration of digital certificate is beyond the scope of this document. (See forum/server/apache2/SSL.)

Installation

Subversion is already in the main repository, so to install Subversion you can simply install the subversion package (seeInstallingSoftware).

If it fails reporting dependencies, please locate the packages and install them. If it reports any other issues, please resolve them. If you cannot resolve the issue, please refer the mailing list archive of those packages.

Server Configuration

This step assumes you have installed above mentioned packages on your system. This section explains how to create SVN repository and access the project.

Create SVN Repository

There are several typical places to put a Subversion repository; most common places are: /srv/svn, /usr/local/svn and /home/svn. For clarity's sake, we'll assume we are putting the Subversion repository in /home/svn, and your project's name is simply 'myproject'

There are also several common ways to set permissions on your repository. However, this area is the most common source of errors in installation, so we will cover it thoroughly. Typically, you should choose to create a new group called 'subversion' that will own the repository directory. To do this (see [AddUsersHowto] for details):

  1. Choose System > Administration > Users and Groups from your Ubuntu menu.

  2. Click the 'Manage Groups' button.
  3. Click the 'Add' button.
  4. Name the group 'subversion'
  5. Add yourself and www-data (the Apache user) as users to this group
  6. Click 'OK', then click 'Close' twice to commit your changes and exit the app.

You have to logout and login again before you are a member of the subversion group, and can do check ins.

Now issue the following commands:

   $ sudo mkdir /home/svn
   $ cd /home/svn
   $ sudo mkdir myproject

The SVN repository can be created using the following command:

  $ sudo svnadmin create /home/svn/myproject

And use the following commands to correct file permissions:

   $ cd /home/svn
   $ sudo chown -R www-data:subversion myproject
   $ sudo chmod -R g+rws myproject

The last command sets gid for proper permissions on all new files added to your Subversion repository.

If you want to use WebDAV as an access method described below, repeat the chmod -R g+rws myproject command again. This is because svnadmin will create directories and files without group write access. This is no problem for read only access or using the custom svn protocol but when Apache tries to commit changes to the repository linux will deny it access. Also the owner and group are set as root. This can be changed by repeating the chown and chgrp commands listed above.

Access Methods

Subversion repositories can be accessed (checkout) through many different methods-on local disk, or through various network protocols. A repository location, however, is always a URL. The table describes how different URL schemas map to the available access methods.

Schema

Access Method

file:///

direct repository access (on local disk)

http://

Access via WebDAV protocol to Subversion-aware Apache 2 web server

https://

Same as http://, but with SSL encryption

svn://

Access via custom protocol to an svnserve server

svn+ssh://

Same as svn://, but through an SSH tunnel

In this section, we will see how to configure SVN for all these access methods. Here, we cover the basics. For more advanced usage details, you are always recommended to refer the svn book.

Direct repository access (file://)

This is the simplest of all access methods. It does not require any SVN server process to be running. This access method is used to access SVN from the same machine. The syntax is as follows:

  $ svn co file:///home/svn/myproject
            or
  $ svn co file://localhost/home/svn/myproject

NOTE: Please note, if you do not specify the hostname, you must use three forward slashes (///). If you specify the hostname, you must use two forward slashes (//).

The repository permission is dependant on filesystem permission. If the user has read/write permission, he can checkout/commit the changes to the repository. If you set permissions as above, you can give new users the ability to checkout/commit by simply adding them to the Subversion group you added above.

Access via WebDAV protocol (http://)

To access the SVN repository via WebDAV protocol, you must configure your Apache 2 web server.

First install the following package libapache2-svn (see InstallingSoftware).

NOTE: If you have already tried to install the "dav" modules manually, package installation may fail. Simply remove all files beginning with "dav" from the mods-enabled directory, then remove and install the package again. Let the package put files in the correct place, then edit your configuration.

You must add the following snippet in your /etc/apache2/mods-available/dav_svn.conf file:

  <Location /svn/myproject>
     DAV svn
     SVNPath /home/svn/myproject
     AuthType Basic
     AuthName "myproject subversion repository"
     AuthUserFile /etc/subversion/passwd
     <LimitExcept GET PROPFIND OPTIONS REPORT>
        Require valid-user
     </LimitExcept>
  </Location>

NOTE: The above configuration assumes that all Subversion repositories are available under /home/svn directory.

TIP: If you want the ability to browse all projects on this repository by going to the root url (http://www.serveraddress.com/svn) use the following in dav_svn.conf instead of the previous listing:

  <Location /svn>
     DAV svn
     SVNParentPath /home/svn
     SVNListParentPath On
     AuthType Basic
     AuthName "Subversion Repository"
     AuthUserFile /etc/subversion/passwd
     <LimitExcept GET PROPFIND OPTIONS REPORT>
        Require valid-user
     </LimitExcept>
  </Location>

NOTE: If a client tries to svn update which involves updating many files, the update request might result in an errorServer sent unexpected return value (413 Request Entity Too Large) in response to REPORT request, because the size of the update request exceeds the limit allowed by the server. You can avoid this error by disabling the request size limit by adding the line LimitXMLRequestBody 0 between the <Location...> and </Location> lines.

NOTE: To limit any connection to the SVN-Server (private SVN), remove the lines <LimitExcept ...> and </LimitExcept> (i.e. leave only the "Require valid-user" line).

Alternatively, you can allow svn access on a per-site basis. This is done by adding the previous snippet into the desired site configuration file located in /etc/apache2/sites-available/ directory.

Once you add the above lines, you must restart apache2 web server. To restart apache2 web server, you can run the following command:

  sudo /etc/init.d/apache2 restart

Next, you must create /etc/subversion/passwd file. 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:

  sudo htpasswd -c /etc/subversion/passwd user_name

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:

  sudo htpasswd /etc/subversion/passwd second_user_name

If you are uncertain whether the passwd file exists, running the command below will tell you whether the file already exists:

  cat /etc/subversion/passwd

Now, to access the repository you can run the following command:

  $ svn co http://hostname/svn/myproject myproject --username user_name

It prompts you to enter the password. You must enter the password configured using htpasswd command. Once it is authenticated the project is checked out. If you encounter access denied, please remember to logout and login again for your memebership of the subversion user-group to take effect.

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://)

Once the SVN repository is created, you can configure the access control. You can edit /home/svn/myproject/conf/svnserve.conf file to configure the access control.

NOTE: svnserve.conf is sensitive to whitespace, be sure not to leave any whitespace at the start of a line or it will not be able to read the file.

For example, to setup authentication you can uncomment the following lines in the configuration file:

  # [general]
  # password-db = passwd

After uncommenting the above lines, you can maintain the user list in passwd file. So, edit the file passwd in the same directory and add new user. The syntax is as follows:

  username = password

For more details, please refer the file.

Now, to access SVN via svn:// custom protocol either from the same machine or different machine, you can run svnserver usingsvnserve command. The syntax is as follows:

  $ svnserve -d --foreground -r /home/svn
    # -d -- daemon mode
    # --foreground -- run in foreground (useful for debugging)
    # -r -- root of directory to serve

  For more usage details, please refer,
  $ svnserve --help

Once you run this command, SVN starts listening on default port (3690). To access the project repository, you must run the following command:

  $ svn co svn://hostname/myproject myproject --username user_name

Based on server configuration, it prompts for password. Once it is authenticated, it checks out the code from SVN repository.

To synchronize the project repository with the local copy, you can run update sub-command. The syntax is as follows:

  $ cd project_dir
  $ svn update

For more details about using each SVN sub-command, you can refer the manual. For example, to learn more about co (checkout) command, please run:

  $ svn help co
Start svnserve at bootup

One can start the svnserve daemon at bootup using an initd script. Look at Michał Wojciechowski Blog post for instructions and a good initd script for svnserve.

Start svnserve at bootup using xinetd

An alternative method to run svnserve at startup is to install xinetd, and then add the following line to /etc/xinetd.conf (replacing 'svnowner' and '/home/svn' with appropriate values)

svn stream tcp nowait svnowner /usr/bin/svnserve svnserve -i -r /home/svn

Access via custom protocol with SSL encryption (svn+ssh://)

It is not necessary to run the SVN server (svnserve) in order to access SVN repositories on a remote machine using this method. However, it is assumed that the SSH server is running in the remote machine with the repository and it is allowing incoming connections. To confirm, please try to login to that machine using ssh. If you can login, then everything is perfect. If you cannot login, please address it before continuing further.

The svn+ssh:// protocol is used for accessing SVN repositories with SSL encryption for secure data transfer. To access a repository using this method, run the following command:

  $ svn co svn+ssh://hostname/home/svn/myproject myproject --username user_name

NOTE: You must use full path (/home/svn/myproject) to access an SVN repository using this method.

Based on the SSH server configuration, it prompts for password. You must enter the password you use to login via ssh. Once it isauthenticated, it checks out the code from SVN repository.

You can also refer the SVN book for details about the svn+ssh:// protocol.

References

------------------------------------------

SubVersion

目录

[编辑]SubVersion服务安装设置

原文出处:https://wiki.ubuntu.com/SubVersion

原文作者:ubuntu.com

授权许可:创作共用协议

翻译人员:XueCan

校对人员:无

适用版本:所有版本

文章状态:翻译中


本文档阐述了如何在 Ubuntu 上设置 Subversion(通常也被称为 svn)。我们假设本文的读者是具有一定经验的 Linux 用户和系统管理员。

[编辑]简介

如果您对 Subversion 还比较陌生,本节将给您一个关于 Subversion 的简要介绍。

Subversion 是一款开放源代码的版本控制系统。使用 Subversion,您可以重新加载源代码和文档的历史版本。Subversion 管理了源代码在各个时期的版本。一个文件树被集中放置在文件仓库中。这个文件仓库很像是一个传统的文件服务器,只不过它能够记住文件和目录的每一次变化。

[编辑]假设

首先我们假设您能够在 Ubuntu 中操作 Linux 的命令、编辑文件、启动和停止服务。当然,我们还认为您的 Ubuntu 正在运行中,您可以使用

[编辑]本文涉及的范围

要通过 HTTP 协议访问 SVN 文件仓库,您需要安装并配置好 Web 服务器。Apache 2 被证实可以很好的与 SVN 一起工作。关于 Apache 2 的安装超出了本文的范围(关于Apache2 的安装可以 另见) ,尽管如此,本文还是会涉及如何配置 Apache 2 使用 SVN。

类似的,要通过 HTTPS 协议访问 SVN 文件仓库,您需要在您的 Apache 2 中安装并配置好数字证书,这也不在本文的讨论范围之中(另见)。

[编辑]安装

幸运的,Subversion 已经包含在 main 仓库中。所以,要安装 Subversion,您只需要简单的运行:

$ sudo apt-get install subversion
$ sudo apt-get install libapache2-svn

如果系统报告了依赖关系的错误,请找出相应的软件包并安装它们。如果存在其它问题,也请自行解决。如果您依然不能解决这些问题,可以考虑通过 Ubuntu 的网站、Wiki、论坛或邮件列表寻求支持。

[编辑]服务器配置

您应该已经安装了上述的软件包。本节将阐述如何创建 SVN 文件仓库以及如何设置项目的访问权限。

[编辑]创建 SVN 仓库

许多位置都可以放置 Subversion 文件仓库,其中两个最常用的是:/usr/local/svn 以及 /home/svn。为了在下面的描述中简单明了,我们假设您的 Subversion 文件仓库放在 /home/svn,并且你的项目名称是简单的“myproject”。

同样的,也有许多常用的方式设置文件仓库的访问权限。然而,这也是安装过程中最经常出现错误的地方,因此我们会对此进行一个详细说明。通常的情况下,您应该创建一个名为“Subversion”的用户组,该组是SVN仓库所在的目录的拥有者。下面是一个快速的操作说明,有关内容请参考相关文档的详细说明:

  • 在 Ubuntu 菜单上选择“系统->系统管理->用户和组”;
  • 切换到“组”标签;
  • 点击“添加组”按钮;
  • 组名为“subversion”;
  • 将您自己和“www-data”(Apache 用户)加入组成员中;
  • 点击“OK”以确认修改,关闭该程序。

或者使用命令完成上述功能(增加组,并且把用户加到组里):

sudo addgroup subversion
sudo usermod -G subversion -a www-data

再或者直接使用命令编辑组文件"sudo vi /etc/group",增加组和成员(不推荐):

$ sudo vi /etc/group

结果看上去,像这样。

$ cat /etc/group|grep subversion
subversion:x:1001:www-data,exp

您需要注销然后再登录以便您能够成为 subversion 组的一员,然后就可以执行签入文件(Check in,也称提交文件)的操作了。

现在执行下面的命令

$ sudo mkdir /home/svn
$ cd /home/svn
$ sudo mkdir myproject
$ sudo chown -R root:subversion myproject

下面的命令用于创建 SVN 文件仓库:

$ sudo svnadmin create /home/svn/myproject

赋予组成员对所有新加入文件仓库的文件拥有相应的权限:

$ sudo chmod -R g+rws myproject

如果上面这个命令在创建SVN文件仓库之前运行,你可能在后续Check in的时候遇到如下错误:

Can't open '/home/svn/myproject/db/txn-current-lock': Permission denied

查看txn-current-lock文件的权限和用户以及组信息,应该类似于:

$ ls -l /home/svn/myproject/db/txn-current-lock
-rw-rwSr-- 1 root subversion  0  2009-06-18  15:33  txn-current-lock

除了权限以外,用户及其组如果不对,则仍然会遇到上述问题,可以再次运行命令:

$ sudo chown -R root:subversion myproject
[编辑]访问方式

Subversion 文件仓库可以通过许多不同的方式进行访问(Check Out,签出)——通过本地硬盘,或者通过各种网络协议。无论如何,文件仓库的位置总是使用 URL 来表示。下表显示了不同的 URL 模式对应的访问方法:

模式
访问方法

file:///
直接访问本地硬盘上文件仓库

http://
通过 WebDAV 协议访问支持 Subversion 的 Apache 2 Web 服务器

https://
类似 http://,支持 SSL 加密

svn://
通过自带协议访问 svnserve 服务器

svn+ssh://
类似 svn://,支持通过 SSH 通道

本节中,我们将看到如何配置 SVN 以使之能够通过所有的方法得以访问。当然这里我们之讨论基本的方法。要了解更高级的用途,我们推荐您阅读《使用 Subversion 进行版本控制》在线电子书

[编辑]直接访问文件仓库(file://)

这是所有访问方式中最简单的。它不需要事先运行任何 SVN 服务。这种访问方式用于访问本地的 SVN 文件仓库。语法是:

$ svn co file:///home/svn/myproject
或者
$ svn co file://localhost/home/svn/myproject

注意:如果您并不确定主机的名称,您必须使用三个斜杠(///),而如果您指定了主机的名称,则您必须使用两个斜杠(//).

对文件仓库的访问权限基于文件系统的权限。如果该用户具有读/写权限,那么他/她就可以签出/提交修改。如果您像前面我们说描述的那样设置了相应的组,您可以简单的将一个用户添加到“subversion”组中以使其具有签出和提交的权限。

[编辑]通过 WebDAV 协议访问(http://)

要通过 WebDAV 协议访问 SVN 文件仓库,您必须配置您的 Apache 2 Web 服务器。您必须加入下面的代码片段到您的 /etc/apache2/mods-available/dav_svn.conf中:

<Location /svn/myproject>
DAV svn
SVNPath /home/svn/myproject
AuthType Basic
AuthName "myproject subversion repository"
AuthUserFile /etc/subversion/passwd
<LimitExcept GET PROPFIND OPTIONS REPORT>
Require valid-user
</LimitExcept>
</Location>

如果需要用户每次登录时都进行用户密码验证,请将<LimitExcept GET PROPFIND OPTIONS REPORT>与</LimitExcept>两行注释掉。

当您添加了上面的内容,您必须重新起动 Apache 2 Web 服务器,请输入下面的命令:

sudo /etc/init.d/apache2 restart

接下来,您需要创建 /etc/subversion/passwd 文件,该文件包含了用户授权的详细信息。要添加用户,您可以执行下面的命令:

sudo htpasswd -c /etc/subversion/passwd user_name

它会提示您输入密码,当您输入了密码,该用户就建立了。“-c”选项表示创建新的/etc/subversion/passwd文件,所以user_name所指的用户将是文件中唯一的用户。如果要添加其他用户,则去掉“-c”选项即可:

sudo htpasswd /etc/subversion/passwd other_user_name

您可以通过下面的命令来访问文件仓库:

$ svn co http://hostname/svn/myproject myproject --username user_name

它会提示您输入密码。您必须输入您使用 htpasswd 设置的密码。当通过验证,项目的文件就被签出了。

警告:密码是通过纯文本传输的。如果您担心密码泄漏的问题,我们建议您使用 SSL 加密,有关详情请看下一节。

[编辑]通过具有安全套接字(SSL)的 WebDAV 协议访问(https:// )

通过具有 SSL 加密的 WebDAV 协议访问 SVN 文件仓库(https:// )非常类似上节所述的内容,除了您必须为您的 Apache 2 Web 服务器设置数字证书之外。

您可以安装由诸如 Verisign 发放的数字签名,或者您可以安装您自己的数字签名。

我们假设您已经为 Apache 2 Web 服务器安装和配置好了相应的数字证书。现在按照上一节所描述的方法访问 SVN 文件仓库,别忘了把 http:// 换成https://。如何,几乎是一模一样的!

[编辑]通过自带协议访问(svn://)

当您创建了 SVN 文件仓库,您可以修改 /home/svn/myproject/conf/svnserve.conf 来配置其访问控制。

例如,您可以取消下面的注释符号来设置授权机制:

# [general]
# password-db = passwd

现在,您可以在“passwd”文件中维护用户清单。编辑同一目录下“passwd”文件,添加新用户。语法如下:

username = password
#(注意行开始不要有多余空格)

要了解详情,请参考该文件。

现在,您可以在本地或者远程通过 svn://访问 SVN 了,您可以使用“svnserve”来运行 svnserver,语法如下:

$ sudo svnserve -d --foreground -r /home/svn
# -d -- daemon mode
# --foreground -- run in foreground (useful for debugging)
# -r -- root of directory to serve
要了解更多信息,请输入:
$ svnserve --help

当您执行了该命令,SVN 就开始监听默认的端口(3690)。您可以通过下面的命令来访问文件仓库:

$ svn co svn://hostname/myproject myproject --username user_name

基于服务器的配置,它会要求输入密码。一旦通过验证,就会签出文件仓库中的代码。

要同步文件仓库和本地的副本,您可以执行 update 子命令,语法如下:

$ cd project_dir
$ svn update

要了解更多的 SVN 子命令,您可以参考手册。例如要了解 co (checkout) 命令,请执行:

$ svn co --help
或者这样
$ svn --help commit
或者直接
☎ svn help co
checkout (co): 从版本库签出工作副本。
使用: checkout URL[@REV]... [PATH]
。。。。。

一个实例:

☎ killall svnserve; svnserve -d -r /home/svn/
/home/svn/lj12-source/conf ☎ dog *
authz:[groups]
authz:lj12 = veexp
authz:[lj12-source:/] <-注意写法。
authz:veexp = rw
authz:@lj12 = rw
authz:* = passwd:[users] <-2个用户和密码。
passwd:veexp = icep
passwd:test = test 
svnserve.conf:[general]
svnserve.conf:anon-access = none
svnserve.conf:auth-access = write
svnserve.conf:password-db = passwd
svnserve.conf:authz-db = authz <-如果不启用authz,则test也可以取出。
☎ svn co svn://localhost/lj12-source --username veexp
认证领域: <svn://localhost:3690> a712643f-661e-0410-8ad4-f0554cd88977
用户名: veexp “veexp”的密码:
A lj12-source/tim.h A lj12-source/en.c
......

认证失败的密码缓冲记录位置,明文密码。到1.6版本,可能使用keyring管理。如果调试密码,直接删除如下文件就可。

~/.subversion/auth/svn.simple/:

eea34a6f7baa67a3639cacd6a428dba4
[编辑]通过具被SSH隧道保护的自带协议访问(svn+ssh://)

配置和服务器进程于上节所述相同。我们假设您已经运行了“svnserve”命令。

我们还假设您运行了 ssh 服务并允许接入。要验证这一点,请尝试使用 ssh 登录计算机。如果您可以登录,那么大功告成,如果不能,请在执行下面的步骤前解决它。

svn+ssh:// 协议使用 SSH 加密来访问 SVN 文件仓库。如您所知,数据传输是加密的。要访问这样的文件仓库,请输入:

$ svn co svn+ssh://hostname/home/svn/myproject myproject --username user_name

注意:在这种方式下,您必须使用完整的路径(/home/svn/myproject)来访问 SVN 文件仓库

基于服务器的配置,它会要求输入密码。您必须输入您用于登录 ssh 的密码,一旦通过验证,就会签出文件仓库中的代码。

您还应该参考 SVN book 以了解关于 svn+ssh:// 协议的详细信息。

[编辑]参考资料

from:https://help.ubuntu.com/community/Subversion

中文版:http://wiki.ubuntu.org.cn/SubVersion#SubVersion.E6.9C.8D.E5.8A.A1.E5.AE.89.E8.A3.85.E8.AE.BE.E7.BD.AE

posted @ 2012-04-29 14:30  .net's  阅读(1043)  评论(0)    收藏  举报