Working in a startup has it’s own quirks. Being one of the first few employees at WisdmLabs I have come to understand this too well. You have to build everything from the grass root level. There’s no one really to guide you and you have to tread with extreme caution. At the same time, it serves you with opportunities and experiences that you would have never imagined of at any fully flourished organization.
One of the first few things that I learned here is that BACKUP happens to be one of the most crucial aspects of software development. And of course I learned it the hard way.
This is how I felt from the inside the first time I lost code due to inexperience. (In hindsight it feels like stupidity but I am going to go with inexperience 😉 )
The first task that I did after rewriting the lost code was to set up a subversioning system. If there was one thing I was never going to let happen again, it was losing code due to a lack of backup.
When Would You Need Subversioning?
1. When Multiple People are Working on the same Project
The thing about multiple people working on the same project is that there is a very good possibility of one developer’s code being overridden by another developer’s code. Now if you don’t have a backup you might just end up losing all your code and you’ll be left with the same expression as mine. Also, there is the additional work that comes with accidently deleted code – REWORK!
Cutting to the chase. With a subversioning system installed the chances of arriving at such a situation is minimized to a great extent as subversioning allows you to view all the changes that are made by all developers working on the code.
2. When You are Developing a Software Product
Another situation in which subversioning can be considered as essential is while developing a software product. A product is all about growth, changes, updates, and versions. With continuous iterations, it becomes essential to maintain a repository which can be referred to when the time come. For example if a new version of your product does not work for some customers then you can provide them with an earlier version of the product from the subversioning repository.
Which are The Scenarios WisdmLabs Uses Subversioning For?
At WisdmLabs, we create a development website for every project we work on. Developers usually work on their localhost and commit their code to SVN when they are ready to do so. When developers commit to SVN, their changes are reflected on the development website. Later software testers test on those development websites and report the issues and bugs found in the system.
As a software development company working on multiple projects simultaneously subversioning becomes crucial on all projects. Here are a few reasons subversioning is crucial for our business.
- Usually, we have multiple developers working on a single project simultaneously. It’s often said that too many cooks spoil the broth. With subversioning, we are defying this old age adage.
- While it only makes sense to use subversioning in every project, it is particularly useful for client projects that have been divided into milestones. It is especially relieving when I am faced with erratic timelines or nitpicky clients.
- Lastly, we use subversion for the development cycle of all our software products. Versions for a product are like milestones for a client project, you gotta keep tracks.
What are the Benefits of Subversion?
Following are some of the many advantages of Subversion.
- It provides a separate environment for developers and testers.
- Code management becomes easier.
- It allows many people to work on the code simultaneously thereby saving on valuable time.
How to Sync Website with Subversion?
Now let’s try to understand how to sync repositories with your websites. In this tutorial, I am assuming that your websites and SVN repositories will be hosted on the same server and you have already installed apache (or nginx) along with the subversion software.
- I am also assuming you have created a website abc.com with root directory as /home/abc/public_html (If you have not yet created a website, then create it NOW! You can do it using cPanel or similar softwares. If you do not have cPanel or a similar software installed then check out how to create a virtual host for Apache and Nginx)
- Fire up the SSH terminal of your server and follow the commands below. Let’s first go to abc directory which can be done by firing command
- Now we have to check the owner of the public_html directory. To do this fire the following command
ls -al public_html
- If the user you are logged in with is different from that of public_html, then fire the following command where userNameHere is the username of public_html directory. By firing this command you will be logged in as user associated with public_html directory. If it asks for a password, enter the password associated with that username.
sudo su - userNameHere -s /bin/sh
- Now using the next command you will have to create a repository inside a directory svn_repository.
- Now let’s go to the public_html directory.
- The first checkout will happen in the svn_repository directory. Here you will have to execute the following command.
svn checkout file:///home/abc/svn_repository
- In order to update website automatically after commit, we will have to register post-commit hook using the following procedure.
cd /home/abc/svn_repository/hooks touch post-commit nano post-commit
- The above command will open up an editor. Add following content in that editor.
#!/bin/sh REPOS="$1" REV="$2" TXN_NAME="$3" svn update /home/abc/public_html --username <svn_username> --password <svn_password> >> /dev/null
Change svn_username and svn_password with your SVN username and password in above content and then paste it in the terminal. Now save the file.
- We will have to make this file executable. To do so fire the following command
sudo chmod +x /home/abc/svn_repository/hooks/post-commit
This completes our configuration. Now checkout the repository in your computer, add some file and commit it. Once you have committed it, you will be able to access it via your browser. For example, if you have committed xyz.html to the repository then you will be able to access it via abc.com/xyz.html.
So that’s how you should sync your website with subversion. If you follow all the steps given above in the order that they have been given you will be able to achieve the required result effortlessly.
That’s all from my end today. I hope you found this post helpful. I have been doing a lot of RnD lately. Hopefully I’ll find the time to translate that into posts.
Until then, goodbye!