This article is about installing Subversion on a Linux Mint machine and using Subversion without Apache or SSH or WebDAV. In other words this is a bare bones installation and this kind of setup is only recommended if you are installing it on a local network or a private computer which is not accessible on public networks.
sudo apt-get install subversion
This will install the latest subversion package on your system.
You can designate any folder in your system as the subversion repository root. Lets use /var/subversion as the root folder
sudo mkdir /var/subversion
Change ownership as required. Lets set a current user as the owner
chown amit /var/subversion
Start the server as a daemon. You can set it to autostart by putting it in /init.d as is the general preference.
sudo svnserve -d -r /var/subversion
ADDING A REPOSITORY
There are two approaches. Either you can put multiple projects in the same repository by having them in separate folders or you can set each project to reside in its own repository. We will use the latter approach.
svnadmin create dummyproject
This creates a repository under the subversion folder. It will contain files and folders which subversion creates. Do not ever manually alter anything in these folders except for the conf folder. The other folders are used by subversion and manually changing something in them may corrupt the repository.
In the conf folder there will be 4 files:
Open authz and add the following lines:
amit = rw
The above line allows the user amit to have read-write access to this repository
Open passwd and add the following lines
amit = mypassword
By doing this you are setting up a username-password pair to access this repository. You can setup multiple users of course.
Open svnserve.conf and add the following lines:
anon-access = none
auth-access = read
auth-access = write
authz-db = authz
password-db = passwd
The lines are self-explanatory. We are not allowing any anonymous access to the repository. A user needs to supply authentication to browse or make changes in the repository.
CONNECTING FROM A SVN CLIENT
Now we are done with setting up the server side of things. Lets see how to use it from the client side. Windows users can use TortoiseSVN client to connect to the svn server and there are other GUI based clients for other platforms. Here we are using the bare bones approach and going to use the command line.
We are going to use the svn:// url format even if the client and server are on the same machine. Lets assume the IP of the svn machine is 192.168.1.80
Assume you already have a project in /home/myproject which you now want to add into SVN. There are two steps to do here. We import all the project files and folder into SVN and then we do a checkout. At the end of checkout your repository is updated with the latest files and you have a working copy.
svn import svn://192.168.1.80/dummyproject/trunk –username amit –password mypassword
This will import the current folder recursively into the repository. Note that the svn path has a /trunk added in the end. This is just a SVN convention where a repository has three standard folders: trunk, tags and branches. You dont need to specify /trunk at the end. You can simply use svn://192.168.1.80/dummyproject if required.
After the import, you need to do a checkout. You should empty the folder before you do a checkout as svn might complain that the folder is not empty or it might have file conflicts. So on the safe side, copy the contents into a different folder and delete everything from /home/myproject
Do a checkout now:
svn co svn://192.168.1.80/dummyproject/trunk .
The last argument in the co command is the local path where the checkout should happen. In this case since I put the svn into a /trunk subfolder , if I didnt specify a local path in checkout it would do a checkout in /home/myproject/trunk . If I specify that I want the checkout to happen in the current path ( the dot ) then it does a checkout in /home/myproject
You now have a working copy in /home/myproject and the latest revision in the repository .
SVN has a lot of commands and concepts which you need to know before you can really use it properly and its outside the scope of this article. But the very basic commands are commit and update.
A commit is when you update changes from your working copy into SVN and an update is the reverse – when you want to update your working copy with the latest changes in SVN.
Once you have made some changes to existing files, do a commit with an optional message
svn commit -m “My message”
If you have added new files, then you need to run the add command
svn add newfilename
You can use wildcards to specify multiple files in a single command. Then run a commit again.
Deleting files is tricky in SVN. You cannot simply delete a file from your working copy, because then Subversion will replace it back from the repository. The correct way is to use the svn delete command and do a commit
svn delete myfile
svn commit -m “File deleted”
In case you accidentally delete a file from your working copy, then you can restore it back by running the update command
The update command is mostly useful when someone else is working on the project and you want to update your working copy with those changes. Or if you are working on two copies of the project on two different machines and want to keep the changes in sync.
The best manual for Subversion is available on http://svnbook.red-bean.com/