Search code examples
phpnetbeansversion-controlmercurialtortoisehg

NetBeans, TortoiseHG and version control on PHP projects


We are a team of two developers developing PHP/MySQL applications. We've been using Netbeans/TortoiseHG for some time now, but as our projects do not cross, and development is fairly simple and straight forward, we've been using Mercurial mainly to have a central repository where both of us can find the latest version of whatever the other one is working on.

So far, the development path follow very simple steps:

  1. Create project in Netbeans
  2. Create repository in Tortoise
  3. Have a clone of this Tortoise repository in a shared space
  4. As development progresses, commit, push (in case one of us had to make changes to the other's projects in his absence), and pull.

As you can see, very simple and limited, but sufficient for our needs.

But now I'm working on a project that will require real version-control. In my case, this means that I will need to keep two separate and independent development paths, one for production and one for development:

  • one version (let's call 1.0) would reflect what is in production and will be updated as needed. Development here would be based on errors found in production and requests from users; (these changes would probably have to propagate to "the other version";
  • the other version (let's say 2.0), would be the place where I would work on new features that will not be in production for at least a few months..

My question is, how should I set up this project, from directory structure to NetBeans and TortoiseHG? What are the best practices?

By the way, I'm using NetBeans IDE 7.3 and TortoiseHG 2.7.1 with Mercurial-2.5.2

To give you a sense of where I am, I've played a little bit with branching in TortoiseHG but the results I got were not what I expected (I didn't get the two independent sets of files I hoped, as to work on them independently). I don't know if I was doing it wrong or if branching is not what I need.

So, having failed with branching and not knowing what to do, I thought about creating multiple folders/directories inside the same Netbeans project, one for each version and name each folder after its version (version1.0, version2.0, version3.0...). Then I would place the whole file structure of the project inside each of these folders and keep a manual control of the updates, i.e., after any change, I would manually copy the files from one "folder version" to another, as needed. But this looks so wrong in so many levels.

Based on what I wrote, can you tell me how to correctly approach this? What are the best practices? Or could you point me in the right direction where I can find tutorials explaining how to get there?

Thanks, S.


Solution

  • Thank you CosLu,

    You placed me in the right path and now I understand how this works...

    The branching is the way to go, but it does not create a second project in your NetBeans Environment. Instead, you have as many branches in TortoiseHG/Mercurial as you need, and only one of them at a time will show in your NetBeans environment.

    In few steps, this is how I understand it works.

    1. You create your project in NetBeans and TortoiseHG (create might not be the best term)
    2. You work on your project and commit your changes.
    3. When you get to a point that you want to start working on a second path in the project, do this:
    4. Commit all your changes so far
    5. Create a new branch: In NetBeans, you can right-click on the project, followed by Mercurial -> Branch -> Create Branch (give it a name)
    6. Work on changes for this new branch
    7. Commit your changes. If you go now to TortoiseHG, you will see a new branch showing.
    8. If you want a 3rd branch, repeat steps 3 to 7.

    To work on a different path (branch) from the one that is currently active, simply go to TortoiseHG, right-click at the head of the branch you want to work, and select "Update". Click OK in the confirmation dialog box and you will be ready to go. In your NetBeans environment, your project will reflect that branch.

    It's very important that you pay attention on which branch is active at that moment, so you do not make changes to the wrong branch.

    The only part of this puzzle that I don't know yet is how do I commit selective changes from one branch to another. For example, if I make changes to my production system and want it reflected on my development one, without merging them, how do I do it? But this is beyond the scope of this question...