Tuesday, April 15, 2008

Mercurial in NetBeans - Working with Remote Repository

(You will need Mercurial installed in windows to see the things in this article working. We covered installing Mercurial in windows in an earlier post here)

Support for remote repositories in NetBeans IDE 6.1 is limited to updating and pulling. I wish I could have done all the required things only in NetBeans IDE but unless full support is available in NetBeans IDE we will use NetBeans IDE and TortoiseHg windows shell client to achieve our goals.

Let us start with the free Mercurial project hosting site FreeHg. FreeHg provides free sign up and hosting of your mercurial repositories. If you do not have an account yet sign up now.

Let me create a new repository named myhgtest

After clicking the button Create repository for tusharvjoshi I can see the repository created and displayed on the web page with its web address as http://freehg.org/u/tusharvjoshi/myhgtest/

This is an empty but initialized Mercurial repository for me on remote server. To work with this repository I will clone it to my workstation.

Right clicking in empty space of My Computer window will bring windows context menu with TortoiseHg > Clone a repository option.

I will name my repository as myhgtest and will provide the remote web address for my source path

TortoiseHg creates a new folder and clones the remote repository in that folder.

NetBeans IDE cannot create a new NetBeans project in an existing directory yet. I will have to create a dummy project for this purpose. Let me create a project with name myhgtest-temp just for creating the project skeleton files.

Now as the project skeleton is ready as seen in the image

I will copy all the files in this folder myhgtest-temp to my cloned repository folder myhgtest. Now when I choose Open project command in NetBeans IDE it will show my cloned repository also. Open that project.

We can see Netbeans IDE identifies that this project is under Mercurial version control. Remember we have not yet committed the NetBeans project configuration skeleton files, so the files are shown in a different color.

Let us commit the files to the repository. Committing, Updating can be done from within the Netbeans IDE.

Now we have all the files committed to the local repository. Now when I am done with my development I want to share this version with my friends. The push command to remote repository is not supported in NetBeans IDE 6.1 yet and gives an error for me.

I choose to right click in the folder window and TortoiseHg > Synchronize... option

The synchronize window has an option of Push. Let us choose that option

As soon as I choose the Push option TortoiseHg asks for the password for the repository. Cloning can be done without password but pushing to a repository requires a password in FreeHg server.

It successfully pushed the files. How to check whether the files are really updated on the remote server?

When I refreshed the project page in my browser I could see the new change-set available on the changes section of the project.

This is how we can share a Mercurial project through a remote server. All the developers can clone the project and update the project through Push commands. NetBeans IDE provides identification and local commands to work with the local Mercurial repository copy.

I will like to have all the features in NetBeans IDE as I said earlier so that TortoiseHg is no more needed. I believe this will be very soon.

with regards
Tushar Joshi, Nagpur

1 comment:

  1. Yes I think one of the most frustrating things with Mercurial is that you have to log onto the server and create a new repository. I hate not being able to just create a netbeans project, and submit it to a new repository on the server.

    btw. making a commit is a pain in the ass, you should remove the need to log into an account just to post a comment... annoying.