Saturday, March 17, 2012

An Afternoon with Version Control

I've had a few interviews that have stressed introductory-level concepts, such as data structures and algorithms. It has shown me how in the past couple of years I've gotten out of practice with some of these ideas.

With that in mind, I decided to write a few of my own data structures. My thinking was, by implementing my own I will be more aware of how lists, maps, and others really work, which would allow me to make good decisions as to which one to use when problem-solving.

I started writing my own List implementation, but I realized I was doing things wrong.

First off, I implemented without much of a plan, which wasn't really a huge misstep, but I realized that I could use this opportunity to practice some test-driven development. So I wrote a few tests and worked on getting them to pass.

I realized my second mistake immediately after: I didn't set up any version control. I had been hacking away and I went to commit my code, but I realized I couldn't. So I stopped and backed up.

Setting up a repository took longer than I thought it might, mainly because I've never really set up my own. I've used BitBucket before, so I went there and made my own repository. I tried cloning it, which I could do easily enough through the Mercurial Eclipse plugin, but I couldn't create files; Eclipse screamed about how "the source folder is not a Java source folder." I looked at it for a bit and was somewhat stumped.

Instead of solving that problem, I thought perhaps I'm doing things backwards. So I looked into creating a repository locally and pushing that. I searched the internet about how to turn a project into a local repository and found TortoiseHG Workbench. After installing it, all seemed to be going well, until I tried to push changes. Nothing seemed to be getting pushed, and the BitBucket repository wasn't being updated. The error I was getting was pretty vague ["push aborted, ret 1"]. I'm sure it was user-error, but this path didn't seem to be getting me any closer to my goal.

Hmmm...

I backed up and went to the Mercurial wiki and found the help I needed. It looked like I would need to use the command line, which worried me slightly. I haven't had a great deal of experience utilizing terminal commands, but I figured out what I needed to do and successfully pushed a few changes.

To summarize:
Before you can commit anything, you should set up the URL of the repository in the .hgrc file. Per the recommendation of the tutorial I was following, I set up my username and repository location as follows:

[ui]
username = Josh Hurst <myEmail>
[paths]
default = https://bitbucket.org/..../

Then, I performed the following:

  1. via the command line, navigate to the project folder you wish to have as your repository 
  2. execute hg init
  3. execute hg status, which shows you which files have not yet been "added" to the repository
  4. execute hg add, adding the files to the commit
  5. execute hg commit -m <Insert your commit message here, exclude angular brackets>
  6. execute hg push, which will push to the URL you've provided

This is one of those things that once you do it, it's much, much easier to do again. I'm probably not using all of the features available to me, but setting up my own sandbox to commit things and have access to them, regardless of my latitude and longitude is awesome.

Hopefully as I work on this, I can get some experience with the terminal. It's an area where I can grow as a developer, and my inexperience with it shows how I grew up using GUIs (Windows 3.1, Win95, etc) and not the command line. It makes me wonder how the next generation of technology users will fare due to the huge push toward touchscreens and tablet PCs.

1 comment:

  1. Note that you don't need a third-party or Web-based host for Mercurial. When you create your repository locally, it's a fully-functional repository. If you want to push that somewhere else for some reason, you can push it to another repository on a physical disk. This won't help you if you're trying to push things offsite in case of hardware failure, of course---just pointing out that you don't need to rely on BitBucket if all you're doing is an exploratory solo project.

    ReplyDelete