DZone 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

Snippets has posted 5883 posts at DZone. View Full User Profile

Svn Cd.

12.06.2006
| 3053 views |
  • submit to reddit
        Shell Alias that allows you to cd into a svn repo, without checking out the entire repository. 
Since, each checkout or update is done non recursively, the entire repository is not checked out.   

function scd() {
    # Get SVN repo url and remove the parts we don't need.
    if svn ls `svn info |grep "URL: http://"|cut -c6-`/$1
    then
        # Break apart each entry in the path 
        for partial in $(echo $1 | tr '/' ' ')
        do
            # non recursively update that part and cd
            #  into the direcotry. 
            svn update -N $partial
            # Should check to see if the last entry is a 
            # file or directory before cd'ing into it.
            # Could do it like so:
            # if file $partial | grep -e ': directory$'
            # then
            #  cd $partial
            # fi
            # But I have not tried it out.
            cd $partial
        done
    fi
}

The way one would use it is. First checkout you repo as normal except use a -N flag as well.
For example:
svn co -N http://www.example.com/repo/ /home/example/repo

Now say yoy wanted to go to your trunk, you would do:
cd /home/example/repo
scd some/long/path/to/a/set/of/modules/module1/trunk

You would now be in some/long/path/to/a/set/of/modules/module1/trunk everything but trunk checked out.