(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
Tuesday, April 15, 2008
Mercurial in NetBeans - Working with Remote Repository
Saturday, April 12, 2008
Mercurial in NetBeans - Using Mercurial and cloning
I tried experimenting in NetBeans IDE 6.1 Beta for Mercurial support. Now as the NetBeans IDE 6.1 Release Candidate 1 is available I tried to work with this new version and found some changes in the arrangements of the Mercurial menu. Now onwards we will see the features of NetBeans IDE 6.1 RC1 on this blog as this is the latest available release.
If you try to run any Mercurial command on NetBeans IDE when Mercurial is not installed or not available in the Windows executable search path then NetBeans shows a dialog box saying no support for Mercurial.
Mercurial should be already installed to see the things in this post happening. In an earlier post we covered the installation of Mercurial on Windows. The version of Mercurial we installed was not the version NetBeans was expecting so it displayed a dialog box saying this module was not expecting this Mercurial version but it allows to continue with the version we have.
Choosing Yes will tell NetBeans to try anyway.
I created a new sample project "BankExample" for the test run. After right clicking on the project name we can see menu with Versioning > Initialize Mercurial Project.
Choosing this option will initialize Mercurial repository in the project directory. Mercurial will create a folder named ".hg" in the project folder. This is the Mercurial repository where it will store all the configuration and version control material.
You can see the Mercurial initialization output on the output window.
Unlike Subversion Mercurial will not create .hg folder in all the sub folders. This is one feature I liked very much of Mercurial.
The Mercurial repository is created but the files in the directory are not yet tracked by the Mercurial system. We must commit all the files to the repository first to tell Mercurial to keep version information, which it does in terms of change-sets.
The project explorer shows visual clues by showing icons with the file and package names.
We can commit the files by right clicking the project and choosing the Mercurial > Commit... option
The commit dialog box shows all the files that will be committed to the repository. Here we have choice to change the behaviour of the commit command for different files. We can set some files not to commit. We are required to type a message for commit.
We should commit our code often as we develop the project. This commit is made in the local Mercurial repository crested in the project folder. This is just like maintaining our repository locally with the project.
To check the sharing options of the Mercurial version control system we should clone the project repository. Cloning makes a replica of the project repository and also sets a reference to the original copy of the repository as default push and pull target. Once the project is cloned then the original and the cloned copy can share the version information by commands push and pull.
The command for cloning is available at top menu Versioning > Mercurial > Clone (project name)
NetBeans suggest a name for the clone and also offers to make the new cloned project as main project. 
We can see the project cloned in folder BankExample_clone0 and opened in the NetBeans IDE side by side to the original project.
When I changed a file in the cloned project and committed to the repository I can now check pushing the information back to the original repository.
Again Versioning > Mercurial > Share > Push to - default option will allow me to push the changes to the original repository from where I had cloned this repository.
Ideally the projects will be made available on web for sharing by people. People can share the updates to the originally repository by cloning the projects on their workstations. The local copy can be updated by update or pull command from the original repository any time.
with regards
Tushar Joshi, Nagpur
Friday, April 11, 2008
Mercurial in NetBeans - Installing Mercurial in Windows
Mercurial is a distributed version control system. It allows us to maintain source versions in a distributed way. This means we can maintain version information locally in a Mercurial repository and can share this information with others easily. Typically in big projects the topology of sharing of repositories get planned and the repositories are laid out like a tree.
There is one main repository maintained and the developers clone the repositories on their work stations. Cloning means making a replica of the repository on another place. This makes the full Mercurial repository available with the source on local workstation. The origin of the clone is configured as default push path.
Mercurial can be taken as a source control repository server available with in local workstation. This server can share its data with up-link server from where it was cloned in an easy command called as push.
Distributed version control system has become popular lately due to its ease of use all the goodness of copy-merge type of systems and also distributed architecture. This means no central server from where all will have to checkout the projects. This becomes a distributed tree of the project with each developer having his own copy of the server and these servers then collaborate with each other.
NetBeans IDE has support for Mercurial. Actually even the NetBeans code base is now shifted to a Mercurial repository.
Let us see installation of Mercurial system on Windows. Useful information is available on the MozillaWiki Mercurial page. I figured out some missing points to make them work which we will see. We will need some software installers as follows:
1. Mercurial Windows Binary
2. ActiveTcl Installer for hgk
3. hgk.tcl script for "hg view" GUI interesting visualization of repository
4. TortoiseHg Windows Shell client installer
The installation of Mercurial Binary is straight forward.
For windows the installer starts a wizard.
We need to keep on responding with Next. The last page asks whether we want the windows path to be updated. This is a good idea and shall be checked out so the Mercurial command becomes available on command prompt from all the directories.
Once Mercurial is installed I checked the installation by opening a command prompt and typing hg command. It showed the usual output from Mercurial command about the usage of Mercurial. This ensures that I have a good Mercurial installation on my Windows machine now.
Mercurial and GIT are very similar systems. GIT people use a command gitk for visualization of the GIT repository and this command is also available in Mercurial as "hg view". In windows making this command work needs Tcl installed. ActiveTcl distribution makes the Tcl toolkit available in windows.
ActiveTcl provides a installation wizard.
The wizard is simple and easy to follow.
The Registry Settings part is important and registering the tcl extension is important for the tcl files to work.
The hgk file shall be renamed to hgk.tcl and copied to the Mercurial directory. As the Mercurial directory is already in the windows path this will make the hgk file available in path. 
Mercurial has a extensions system to work with external command. In the Mercurial.ini file we need to add one line as shown for hgk to work as an extension
At the end of the Mercurial.ini file add one [hgk] section as shown to make the hgk.tcl file path available to Mercurial.
This will ensure that we can run "hg view" command now. lastly we will install the TortoiseHg shell client for windows. Tortoise products are superb products for CVS, SVN and now also for Mercurial. They make task like creating repositories and working with them piece of cake.
Once you start the installer the wizard will ask questions and in minutes you will have tortoise shell client installed on windows.
Let us see how to work with the Mercurial repositories in the next post. We will use Mercurial repositories in NetBeans IDE to check the Mercurial support from NetBeans.
with regards
Tushar