Subversion

From Schmid.wiki
Jump to: navigation, search

Contents

Cheat Sheet

Create new branch:

svn cp $SVNPATH/trunk/ $SVNPATH/branches/my_branch -m "created private branch"
svn up

Merge trunk changes into branch (add -x -w to ignore whitespace):

svn merge $SVNPATH/trunk/

Test and build and then:

svn ci -m "merged trunk changes into my_branch"

Reintegrate branch into trunk (add -x -w to ignore whitespace):

svn merge $SVNPATH/trunk/

Test and build and then (add -x -w to merge command to ignore whitespace):

svn ci -m "final merge of trunk changes into my_branch"
cd ../../trunk
svn up
svn merge --reintegrate $SVNPATH/branches/my_branch/

Build and test, and then:

svn ci -m "merged my_branch into trunk"
svn rm $SVNPATH/branches/my_branch -m "removed my_branch after reintegration"

Server path has changed:

svn switch --relocate https://server.org/repos/ https://newserver.org/repos/ .

Branching and Merging

Reintegration Problem

At certain times, you get the following error, even though you have merged trunk changes to branch:

svn: Cannot reintegrate from 'https://some.server/branches/branch' yet:
Some revisions have been merged under it that have not been merged
into the reintegration target; merge them first, then retry.

Older versions of subversion seem to cause mergeinfo problems with mergeinfo properties for individual files. This problem can be detected by recursively listing properties in the branch:

svn pl -R $SVN/branches/branch/|egrep -B 4 svn:mergeinfo

If individual files and subdirectories have mergeinfos, you can delete them:

svn pd -R svn:mergeinfo branch/subdirectory_with_mergeinfo/

and commit the changes.

Gentoo Linux

Configuration

Create a Repository

Log in to the server where your subversion repository should be, and:

$ svnadmin create svn
                   |_______ directory name for repository

Importing Project

Log in to where your project is located and:

$ svn import /path/to/project/dir svn+ssh://servername:/home/username/svn/dirname -m "message"

Important note: 'dirname' in the above examples corresponds to module in CVS

Checking out Project

$ svn co svn+ssh://server:/home/username/svn/dirname /path/to/local/dirname

An example:

$ svn co svn+ssh://server:/home/username/svn/python python

Berkeley DB Error

When the Berkeley database system was upgraded to a newer version, I got the error:

svn: Commit failed (details follow):
svn: Berkeley DB error while opening environment for filesystem /home/schmid/svn/db:
Invalid argument
svn: bdb: Program version 4.2 doesn't match environment version

I logged into the subversion server and looked at the shared library dependencies of subversion:

$ ldd `which svn`
...
libdb-4.2.so.2 => /usr/local/lib/libdb-4.2.so.2 (0x28158000)
...

It seems that the repository was created with Berkeley database version 4.1, and my web hotel upgraded to 4.2. This command fixed it:

$ svnadmin recover [repository]

Convert to FSFS

Our group used Subversion on the university, but we ran into all kinds of problems with the Berkeley Database. So I tried converting it to the FSFS format instead:

$ mv repository oldRepository
$ svnadmin create --fs-type=fsfs repository
$ svnadmin dump oldRepository | svnadmin load repository

This way of converting a repository is extremely cool!

post-commit Hook Script Example

Create file post-commit in /var/svn/repos/hooks/:

#!/usr/bin/env ruby

# Configuration
$htdocs_doxygen_path_prefix = '/var/www/localhost/htdocs/doxygen'

$repos_path = ARGV[0]
$revision   = ARGV[1]
def repos_changed?(path) `svnlook dirs-changed #{$repos_path}|egrep #{path}` end
def doxygen(repos_path, htdocs_doxygen_path)

    # only update documentation if containing directory has been changed
    if repos_changed?(repos_path) then
        dir = "#{$htdocs_doxygen_path_prefix}/#{htdocs_doxygen_path}/"
        Dir.chdir(dir)
        `svn up && doxygen doxygen.cfg`
    end
end

doxygen('SomeProject', 'SomeProject')

Make it executable by the svn server, something like this:

chown apache:apache /var/svn/repos/hooks/post-commit
chmod 744 /var/svn/repos/hooks/post-commit

Also check that /var/www/localhost/htdocs/doxygen is writable by the svn server.

Usage

Basic Usage

$ cd /path/to/local/checkout
$ svn st              <- status, checks for changes
$ svn up              <- update local checkout
$ svn rm file         <- remove file from repository
$ svn add file        <- add file to repository
$ svn add --force dir <- recursively add all new files in dir
$ svn ls svn+ssh://servername:/home/username/svn

Properties

Each file or directory can have a list of properties set. This includes user-specific ones:

$ svn ps stupidness 7 some_dir/  <- Property Set
$ svn ci some_dir/ -m "added stupidness property"

To retrieve the properties again:

$ svn pl -v some_dir             <- Property List
Properties on 'some_dir':
  stupidness : 7

There is also a few subversion-specific properties, for instance the 'svn:ignore' property:

$ svn ps svn:ignore "*.html" w3m/

If you want to ignore more than one file pattern:

$ svn pe svn:ignore w3m/         <- Property Edit - invokes editor

Edit the file:

*.html
*cache*
*.gz
cookies

And commit:

$ svn ci w3m/ -m "ignore all temporary data"

Set properties for many files at once - the example shows how to set the svn:ignore property on all directories below the current level:

$ vim ignore               <- write your ignore patterns here
$ svn ps -Fignore svn:ignore `find -type d -not -regex ".*\.svn.*"`
$ svn ci -m"sat ignore flag" `find -type d -not -regex ".*\.svn.*"`

Keyword Substitution

vim somefile.txt
This file is $Revision$.
svn propset svn:keywords "Revision Id Date" somefile.txt
svn proplist somefile.txt
Properties on 'somefile.txt':
 svn:keywords
svn ci -m'set revision property'
egrep '\$Revision' somefile.txt
This file is $Revision: 5439 $

Resolving Conflicts

Ignoring local changes:

$ mv [file].r[newest] [file]
$ svn resolved [file]

Backup

$ svnadmin dump [repository] | bzip2 >backup_`date -I`.bz2

Problems

If you experience permissions problems, consult the SVN Book or you might try setting the setuid and setgid bits on the directories in the repos/db:

$ find /path/to/repos/db -type d|xargs chmod ug+s

If anyone has insight on this, please write something here...

Windows

Installation

  1. Download and install TortoiseSVN
  2. Reboot

Configuration

  1. Change settings Subversion settings 1
  2. To use plink with our key Subversion settings 2

Checking out Project

  1. Select checkout... Subversion checkout 1
  2. Enter server and path information Subversion checkout 2
  • Note that the repository path should be absolute, ie. something like svn+ssh://someone@server:/home/someone/svn/dirname
  • Note that 'dirname' should be the same in the 2 boxes if you want to create a new directory with that name.

References

Personal tools