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

2 comments:

  1. Hi,

    My name is Varun Nischal and I'm the NetBeans Contribution Coordinator. Your blog entry would make a fantastic tutorial entry for our Community Docs wiki (http://wiki.netbeans.org/CommunityDocs).

    Would you be willing to contribute it? If you need any help or have any questions, please contact me at nvarun@netbeans.org

    I look forward to hearing from you.

    Thanks,
    Varun Nischal

    ReplyDelete
  2. Am able to initialize a project of an arbitrary size in:

    Product Version: NetBeans IDE 6.5 (Build 200811100001)
    Java: 1.6.0_11; Java HotSpot(TM) Client VM 11.0-b16
    System: Windows Vista version 6.0 running on x86; Cp1252; en_US (nb)

    Only able to 'commit' a project if it is rather small. No large projects (don't know breakover) will commit successfully: shows "Please check Mercurial is installed and on your PATH" error instead.

    However, as I'd installed TortoiseHG for Windows, was able to commit any size project from Windows Explorer using the 'HG Commit' option available from a right click on the selected directory.

    ReplyDelete