Sun Jul 5 17:29:21 PDT 2015

A Subversion (SVN) Tutorial in a Bash Script

It seems that once very few years I have to learn a new revision control system. Once I have learned some basic commmands, I then spend a little bit of time every week explaining how to use the system to others! Meanwhile people spend time trying to explain to me that this or that graphical interface on to of the revision control system is of vital importance. These graphical systems evolve with time, sometimes involve emacs and vim, and typical require ongoing care and attention. But the command line operations stay static...until eventually a decision is made to move to a new system, and the cycle repeats.

This scipt helps with that processes by educating me on how to control the revision control system from the command line, and sometimes it even helps to convey the knowledge about the very few commands necessary to work with a given system, before the need to look things up on the web strikes.

This script creates a subversion (svn) repository and conducts some simple operations on that repository. You can use this script to learn how subversion works, and how to work with subversion. The script will create a svn directory in your home directory, and trunk and branch (called 2xxx-01-01), directories. These can optionally be removed at the end of the script.

function svn_cmd() {
  echo "Comment: " $1
  if [ -z "$3" ]
    echo "Executing: " $2
    echo $1 > tmp.txt
    echo "Executing: " $2 --file tmp.txt
    $2 --file tmp.txt
    rm -f tmp.txt
  echo ""
if [ -d $REPODIR ]
  echo "Repository alread exists, skipping creation"
  echo "(delete $HOME/svn if you want to start from scratch)"
  svn_cmd "Creating repository" "svnadmin create --fs-type fsfs $HOME/svn"
# create, remove, and create the trunk
svn_cmd "What does the repository contain?" "svn ls $REPO"
svn_cmd "Creating trunk dir" "svn mkdir $REPO/trunk" cmt
svn_cmd "What does the repository contain?" "svn ls $REPO"
svn_cmd "Removing trunk dir" "svn rm $REPO/trunk" cmt
svn_cmd "What does the repository contain?" "svn ls $REPO"
svn_cmd "Creating trunk dir" "svn mkdir $REPO/trunk" cmt
svn_cmd "Checkout trunk" "svn co $REPO/trunk"
cd trunk
echo "line 1" > test.txt
# add a file, and a branch
svn_cmd "Adding test.txt" "svn add test.txt"
svn_cmd "Initial commit" "svn commit" cmt
svn_cmd "Creating branches dir" "svn mkdir $REPO/branches" cmt
svn_cmd "Create a branch" "svn copy $REPO/trunk $REPO/branches/2xxx-01-01" cmt
cd ..
# change the file on the branch
svn_cmd "Checkout branch" "svn co $REPO/branches/2xxx-01-01"
cd 2xxx-01-01
echo "line 2" >> test.txt
svn_cmd "Commit on the branch" "svn commit" cmt
svn_cmd "Checking branch history" "svn log -v test.txt"
cd ../trunk
# check the history
svn_cmd "Checking trunk history" "svn log -v test.txt"
svn_cmd "Diff trunk and branch" "svn diff $REPO/trunk $REPO/branches/2xxx-01-01
# remove the trunk and branches directories
svn_cmd "Removing trunk dir" "svn rm $REPO/trunk" cmt
svn_cmd "Removing branches dir" "svn rm $REPO/branches" cmt
svn_cmd "What does the repository contain?" "svn ls $REPO"
cd ..
echo "Enter y to: rm -rf svn trunk 2xxx-01-01"
read a
if [ "$a" = "y" ]; then
  rm -rf $HOME/svn trunk 2xxx-01-01

Comments are closed

If you would like to get in touch with me, please mail zfs at

recent comments

Posted by ZFS | Permanent link | File under: bash
[StumbleUpon] [Digg] [Reddit] [Facebook] [Google]