Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

export certain revision of file from svn

Easier to just cat the revision you want and copy it over rather than try to check out a certain revision.

svn cat -r [REV] mydir/myfile > mydir/myfile

Protect .svn directories using htaccess

// block access to .svn dirs
// should be done server-wide if you can (another snippet)

<IfModule mod_rewrite.c>
  RewriteRule ^(.*/)?\.svn/ - [F,L]
  ErrorDocument 403 "Access Forbidden"
</IfModule>

Protect .svn directories server-wide (Apache)

// protect ".svn" and "CVS" dirs (could add more)
// for server-wide protection; goes in httpd.conf
// there's a separate snippet for .htaccess-based code

<DirectoryMatch "^/.*/(\.svn|CVS)/">
  Order deny,allow
  Deny from all 
</DirectoryMatch>

Start Subversion Repository with Initial Import

// description of your code here

On the server (cannot be done remotely)
svnadmin create /var/svn/repository_name


On the client with the files to check in
svn import svn+ssh://myserver.com/var/svn/repository_name

You MUST use full path if using svn+ssh. If using HTTP, full path is not necessary.

Then erase the entire directory, and checkout the files from Subversion in order to make the current directory a working copy. Be careful and copy the directory to a backup directory before deleting all files and checking out a working copy.
cd ..
mkdir bak_directory
cp -R my_directory bak_directory
cd my_directory
rm -rf *
svn co svn+ssh://myserver.com/var/svn/repository_name .

Don't forget that period at the end of the checkout (co) statement. It will create the directory if you forget the . (current directory) optional parameter which will result in my_directory/my_directory/[your files]

Access subversion repository on Textdrive via ssh

I found it really difficult to get svn via svn+ssh geting to work because I made two erorrs:
I used not my main user. However, only the main user can get shell access necessary for svn via ssh.
I used a wrong path.

In order to get things going set up subversion following the usual directives in the knowledge base and then access your repository like this:
(OS X terminal here)
% svn co svn+ssh://mainuser@yourdomain.tld/home/mainuser/svn/repositoryname/

This should do the trick.

Remember not to use ssh and http(s) at the same time. It's either or.

Syncing Subversion

When there are directories and files that are in a subversion respository, but don't need to be under source control, you must delete them both in the repository and locally.

To delete it locally:

svn delete <dir> --force


To delete it at repository:
svn delete http://cru.textdriven.com/svn/<project_dir>/<dir> -m "<reason for deletion>"


Then perform your commit as per normal:
svn commit -m "<change description>"

wdiff wrapper for svn

#/bin/sh

wdiff $6 $7

Add all new files to Subversion

This solution is shell-agnostic, unlike http://textsnippets.com/posts/show/450, and cleaner than to do a --force. I recommend adding it to a alias in your shell, i.e "sall".

svn st | grep "^?" | awk -F "      " '{print $2}' | xargs svn add


Can be modified to do a svn delete on files you accidentally rm -rf'ed:

svn st | grep "^!" | awk -F "      " '{print $2}' | xargs svn delete

SVN ignore for all assets that don't begin by "_"

svn propset svn:ignore "[!_]*" .

sup: bash script for universal SCM syncing (svn, svk, cvs, darcs, etc.)

I really can never remember if the project I'm in uses svn or cvs or if it's my own local svk mirror, etc. etc. Thus was born 'sup'!

Save and drop into a location that's in your PATH (I use ~/bin, YMMV)

#!/bin/bash
# sup -- a quick bash script to sync w/ various SCM tools
# @author   Jamie Wilkinson <jamie@tramchase.com>

HERE=$(pwd)

## subversion
if [ -e ".svn" ]; then
        svn up
## cvs
elif [ -e "CVS" ]; then
        cvs up -dP
## darcs
elif [ -e "_darcs" ]; then
        darcs pull --all
## svk
elif [ -n "`grep $HERE ~/.svk/config`" ]; then
    svk up
## git
elif [ -e ".git" ]; then
    git pull
## perforce
#   todo
## arch
#   todo
## bzr
#   todo

fi