Versioning with svn, RapidSVN and nautilus context menu
March 7, 2010 Leave a comment
Trying to clean up the mess I test some linux tools to help versioning, instead of renaming files with intuitive names like v1, v2, final-v1 and so. SVN can handle this issue. It maintain the current and historical versions. Despite it be more used to code versioning, it can be applied to any file type. The installation can be made by apt-get tool:
sudo apt-get install subversion
First, let’s introduce some concepts:
- repository: it manages the version history, saving all states sent (commited) to repository
- working copy: the current version of the project, a repository copy with some changes
And the basic structure of subversion:
- trunk: the current version of the working project
- branchs: used to make a test on the current project without corrupt the current version
- tags: store the stable versions of the project, such as 1.0, 2.0
So let’s show a simple case study presented in SVN command line Ultimolog blog (portuguese).
# create repository /tmp# mkdir repository /tmp# cd repository/ /tmp/repository# svnadmin create HelloWorld /tmp/repository# ls -lh /tmp/repository# ls -lh HelloWorld # create a project directory with the standard directory structure: /tmp/repository# cd .. /tmp# mkdir HelloWord /tmp# cd HelloWord /tmp/HelloWorld# mkdir trunk /tmp/HelloWorld# mkdir branchs /tmp/HelloWorld# mkdir tags /tmp/HelloWorld# ls -lh # write a file on trunk directory: /tmp/HelloWorld# cd trunk /tmp/HelloWorld/trunk# echo "" > index.php /tmp/HelloWorld/trunk# cat index.php /tmp/HelloWorld/trunk# ls -lh # import your working project directory to svn (carefull with the three slashes): /tmp/HelloWorld/trunk# cd .. /tmp/HelloWorld# svn import . file:///tmp/repository/HelloWorld/ -m "Importacao Inicial" /tmp/HelloWorld# ls -lh /tmp/repository/HelloWord/ # delete your working project and checkout a working copy from the repository /tmp/HelloWorld# rm * -r /tmp/HelloWorld# svn checkout file:///tmp/repository/HelloWorld/trunk . /tmp/HelloWorld# ls -lh # add a line to file in your working copy, check out the svn status and make a commit /tmp/HelloWorld# echo "" >> index.php /tmp/HelloWorld# cat index.php /tmp/HelloWorld# svn status /tmp/HelloWorld# svn commit -m "index.php modificado" # create a directory, write a file on it, add it to svn and commit: /tmp/HelloWorld# mkdir cpanel /tmp/HelloWorld/cpanel# cd cpanel /tmp/HelloWorld/cpanel# echo "" > cpanel.php /tmp/HelloWorld/cpanel# cd .. /tmp/HelloWorld# svn status /tmp/HelloWorld# svn add cpanel/ /tmp/HelloWorld# svn commit -m "+ Diretorio cpanel" # add a file to this new directory, check svn status, add the file to svn and commit: /tmp/HelloWorld# echo "" > cpanel/user.php /tmp/HelloWorld# svn status /tmp/HelloWorld# svn add cpanel/user.php /tmp/HelloWorld# svn commit -m "+ modulo usuario" # remove "accidentally" a file and check the svn status: /tmp/HelloWorld# rm cpanel/user.php /tmp/HelloWorld# svn status # update to the previous svn commited version (it will bring user.php back): /tmp/HelloWorld# svn update # delete the file user.php on the repository: /tmp/HelloWorld# svn delete cpanel/user.php /tmp/HelloWorld# ls cpanel -lh /tmp/HelloWorld# svn commit -m "- user.php" # roll back to the repository revision 4: /tmp/HelloWorld# svn update -r4 /tmp/HelloWorld# ls cpanel -lh # came back to the current repository revistion (#5): /tmp/HelloWorld# svn update /tmp/HelloWorld# ls cpanel/ -lh # copy file from repository revistion 4 to current version (doesn't work here.. not found error, but I'll follow with the case study): /tmp/HelloWorld# svn copy -r4 file:///tmp/repository/HelloWorld/trunk/cpanel/user.php cpanel /tmp/HelloWorld# ls cpanel/ -lh /tmp/HelloWorld# svn status /tmp/HelloWorld# svn commit -m "user.php recovered" # list the content of the tag and trunk repository directory /tmp/HelloWorld# svn list file:///tmp/repositorios/HelloWord/tags/ /tmp/HelloWorld# svn list file:///tmp/repositorios/HelloWord/trunk/ # launches the first version (1.0) and list tag repository directory again: /tmp/HelloWorld# svn copy file:///tmp/repositorios/HelloWord/trunk/ file:///tmp/repositorios/HelloWord/tags/versao1.0 -m "Launch version 1.0" /tmp/HelloWorld# svn list file:///tmp/repositorios/HelloWord/tags/ # now suppose that this repository is hosted on a server you could make a checkout from other host: /home/user/temp# mkdir HelloWord /home/user/temp# cd HelloWord/ /home/user/temp# svn checkout file:///tmp/repositorios/HelloWord/trunk .
This case study explains most of the svn concepts. I’m not sure if it is possible to make a commit without add each directory manually, which could least some time. The RapidSVN could handle this issue. It consists of a front end tool to manage subversion, which allows to commit an entire directory:
Follows a preview of RapidSVN:
Its usage is very simple, you should create a repository manually (svn create on command line), create a working project directory (mkdir projectname), import it to svn (svn import on command line) and after it you could import both repository and working copy to your RapidSVN.
Almost finishing this post I found an interesting tutorial of Department of Electronic System of Denmark, which presents a very simple way to interact with SVN with nautilus context menu on Ubuntu. Follow the provided instructions to install and configure it:
sudo apt-get install nautilus-script-collection-svn cp -r /usr/share/nautilus-scripts/Subversion ~/.gnome2/nautilus-scripts/
Follow a preview of how it is embedded on Ubuntu:
1. Portuguese tutorial: http://www.ultimolog.com/2007/05/29/controle-de-versao-com-subversion-svn-rapido-e-pratico/
2. SVN Project: http://subversion.tigris.org
3. Rapid SVN Wiki: http://rapidsvn.com/index.php/OnlineHelp:Contents
4. Graphical SVN: http://doc.es.aau.dk/it_services/30/manage_project_files_using_subversion/graphical_svn_in_ubuntu/