Friday, 24 May 2013

HOW-TO: Apply a “baseless merge” in Team Foundation Server 2010 (and 2012)

Another purely technical post on TFS...

The scenario

We wish to migrate code between branches that do not have a branch/merge relationship, in order to expedite urgent changes being made by a project team, without disrupting on-going BAU development work.

Sample branch hierachy/strategy

Imagine the following branching strategy in TFS (visible by connecting to TFS via Visual Studio 2010 or 2012):

Essentially you have a "DEV" branch, which has a "QA" branch, which in turn has a "PROD" branch. DEV is the branch that you would be using for BAU development. As a piece of development matures, you move it into QA, where it is tested by your internal QA team. There may be further changes made in DEV that are moved into the QA branch as the QA team pick up issues. Once the QA team are happy with a packaged of changes, they will move them into PROD, which is essentially the hand-over to the customer. The PROD branch represents the software that the customer has.

Movement between these branches is "change controlled".

The "DEV-ProjectX" branch, is a branch off of DEV, that is being used to develop a package of work that is independent of BAU work that is going on. Perhaps for example, this represents an urgent or complex change that we do not want to get caught up with day-to-day activities in the codebase.

You can visualise this branching strategy by right clicking DEV and then selecting "View Hierarchy":

Sometimes a picture really can say a thousand words - I find that the visualisation tools provided for TFS by Visual Studio really help.

Our objective

So, imagine that in order to "skip" getting caught up in BAU developments, there is a desire to merge code from the DEV-ProjectX branch directly into the QA branch; this expedites the change and avoids getting it mixed up with other on-going development. To achieve this, we follow these steps:
  • Merge changes from DEV-ProjectX into QA using a “baseless merge”. This is a feature of both TFS 2010 and 2012 where a merge can be made into an unrelated branch. History of both the files/branches being merged are retained, but the files/branches do not have a branch/merge relationship:
  • Once DEV-ProjectX passes QA and is released into PROD, a merge should be performed from QA back into DEV, so that on-going development is integrated with DEV-ProjectX as soon as possible.

Baseless merge in TFS 2010

A baseless merge can be performed on a TFS2010 server, but is not available using the VS2010 UI – it is only available using the command line. In the UI, the only target branch available to be merged into, is the one that the source branch was originally branched from. Note in the following image that when you go to merge the DEV-ProjectX branch using VS2010, the "target branch" DDL only has a single entry in it:

This is what the same popup looks like when you go to merge DEV-ProjectX from VS2012:

You can see that you basically get a browse option for both the source and the target, enabling a baseless merge via the UI.

The UI will advise that you are about to do a baseless merge - it gives a little warning, like this:

Once the baseless merge has been performed, there is a link established between the branches, and subsequent baseless merges can be performed from VS2010 (the branch will appear as being available for merging into in the VS2010 DDL).

Visualising the merge

Once you have "checked in" your changes, a neat feature of VS2010 and VS2012 is the ability to visualise the changeset histories. We can even visualise the baseless merge. Right click and "View History" of the branch, and select the event associated with the baseless merge, the follow these steps to get a neat visualisastion of the baseless merge - select the baseless merged changeset and hit "Track Changeset":

Select the associated branches in the "Track Changeset" screen to show all relevant branches:

Hit the "Visualise" button" - the baseless merge is represented by the dashed line:

To get a view of the timeline of the change, hit the "Timeline Tracking" view at the top of the screen:


This approach may be useful if you have not fully migrated to VS2012 yet and want to perform these type of merges without having to use the command line.

Also note that as mentioned earlier, a baseless merge can be in TFS 2010 using the command line - but since VS2012 is available now, I haven't covered that here. 

And finally, (if you are using a branching strategy like the one described above you will already know this I guess) it's worth noting that when making changes QA/PROD branches prior to making them in DEV, those changes should be merged back down into DEV as soon as possible in order to avoid messy business later on.

No comments:

Post a Comment