Subversion techniques

Subversion is great for version control as well as many workflow/deployment processes. Here are some helpful techniques and links.

It’s also great to integrate svn into your issue tracking and other workflow apps, like Trac and Hudson. If your app doesn’t provide svn support, you can use WebSVN.

One of the great things about svn is the ability to use pre and post commit hooks.

post-commit
Find the file post-commit.tmpl in your svn repo and rename it “post-commit” (*nix systems), e.g., /var/svn/repo_name/hooks/post-commit — make sure it has permissions for whatever user will be calling it, e.g., apache. You can try the sample scripts provided or a simple mail script like:

echo "$REPOS $REV" | mail user@domain.com -s"commit notice"

For more advanced processing, it can help to know which files or directories were changed. You can call some svn helper scripts for that:
per-directory: (stackoverflow)

cd /path/to/working_repo
svnlook dirs-changed $REPOS -r $REV | xargs /usr/bin/svn up -N

or change the last line if you want to update per-file:

svnlook changed [REPOS] -r [REV] | sed "s/^....//" | xargs /usr/bin/svn up

You can run whatever filters you like to on the above, like to only update on trunk commits:

if (/usr/bin/svnlook dirs-changed /var/svn/reponame | grep "trunk"> /dev/null) 
then 
    /var/www/scripts/trac-post-commit.sh "$REPOS" "$REV"
fi

then to update Trac, for instance, you would use something like:

/usr/bin/trac-admin /var/www/trac/projects/project_name changeset added "trunk" $REV

check in external svn repo:

svn propedit svn:externals .

then add:

local/path/ svn://external/url/ (grabs HEAD revision)
local/path/ -r# svn://external/url/ (grabs specific revision #)

Leave a Reply